Skip to content
Snippets Groups Projects
Commit 46a77657 authored by richard.petersen's avatar richard.petersen :sailboat: Committed by richard.petersen
Browse files

Improve error handling in case the UI-containers are not accessible

parent a34e2102
No related branches found
No related tags found
No related merge requests found
......@@ -268,6 +268,51 @@ describe('File caching service', function () {
expect(response5.text).to.equal('second')
})
it('checks again for files after an error occurred', async function () {
// we have example.js in both files. the first one will be overwritten and therefore not be called
mockFetch({
'http://ui-server': {
'/manifest.json': generateSimpleViteManifest({
'example.js': { }
}),
'/example.js': td.when(td.func()(td.matchers.anything())).thenReturn(
new Response('UI-container not available', { headers: { 'content-type': 'text/plain' }, status: 503 }),
new Response('Now available', { headers: { 'content-type': 'text/plain' } })
)
}
})
app = await mockApp()
const response1 = await request(app.server).get('/example.js')
expect(response1.statusCode).to.equal(404)
const response2 = await request(app.server).get('/example.js')
expect(response2.statusCode).to.equal(200)
expect(response2.text).to.equal('Now available')
})
it('does not check again, when a 404 occurred', async function () {
// we have example.js in both files. the first one will be overwritten and therefore not be called
mockFetch({
'http://ui-server': {
'/manifest.json': generateSimpleViteManifest({
'example.js': { }
}),
'/example.js': td.when(td.func()(td.matchers.anything())).thenReturn(
new Response('Not found', { headers: { 'content-type': 'text/plain' }, status: 404 }),
new Response('Now found', { headers: { 'content-type': 'text/plain' } })
)
}
})
app = await mockApp()
const response1 = await request(app.server).get('/example.js')
expect(response1.statusCode).to.equal(404)
const response2 = await request(app.server).get('/example.js')
expect(response2.statusCode).to.equal(404)
})
it('only fetches files once, even when requested simultanously', async function () {
let spy
mockFetch({
......
export class NotFoundError extends Error {}
export class NotFoundError extends Error {
constructor (message, options) {
super(message, options)
this.status = options.status
}
}
......@@ -41,7 +41,7 @@ export async function fetchFileWithHeadersFromBaseUrl (path, baseUrl, version) {
if (!response.ok) {
if (response.status === 404) logger.trace(`[Files] "${path}" could not be found on "${baseUrl}". Responded with: ${response.status}`)
else logger.error(`[Files] Unexpected result from file retrieval "${path}" on "${baseUrl}", responded with: ${response.status}`)
throw new NotFoundError(`Error fetching file: ${path}`)
throw new NotFoundError(`Error fetching file: ${path}`, { status: response.status })
}
const result = {
......@@ -101,7 +101,10 @@ export function getFile ({ version, path }) {
}
}
const dataFromServer = await fetchFileWithHeaders({ version, path })
const dataFromServer = await fetchFileWithHeaders({ version, path }).catch(err => {
if (err.status !== 404) delete cache.getCache()[key]
throw err
})
if (redis.isEnabled()) {
logger.debug(`[Files] Store in redis: ${key}`)
const { body, ...rest } = dataFromServer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment