Skip to content
Snippets Groups Projects
Commit aa43d2a5 authored by david.bauer's avatar david.bauer :fire:
Browse files

Change: Error handling improved

parent 1fa1aaaf
No related branches found
No related tags found
No related merge requests found
......@@ -292,7 +292,7 @@ describe('File caching service', function () {
app = await injectApp()
const response1 = await app.inject({ url: '/example.js' })
expect(response1.statusCode).to.equal(404)
expect(response1.statusCode).to.equal(503)
const response2 = await app.inject({ url: '/example.js' })
expect(response2.statusCode).to.equal(200)
......
......@@ -14,7 +14,7 @@ export class VersionMismatchError extends Error {}
*/
export function isVersionMismatchError (err) {
const errors = err instanceof AggregateError ? err.errors : [err]
return errors.reduce((memo, error) => memo && error instanceof VersionMismatchError, true)
return errors.some(error => error instanceof VersionMismatchError)
}
/**
......@@ -24,5 +24,5 @@ export function isVersionMismatchError (err) {
*/
export function isNotFoundError (err) {
const errors = err instanceof AggregateError ? err.errors : [err]
return errors.reduce((memo, error) => memo && error instanceof NotFoundError, true)
return errors.some(error => error instanceof NotFoundError)
}
......@@ -9,11 +9,10 @@ export default async function serveFilePlugin (fastify, options) {
const path = url === '/' ? '/index.html' : url
const { body, headers } = await getFile({ version, path })
reply.headers(headers)
reply.send(body)
} catch (err) {
if (isNotFoundError(err) || isVersionMismatchError(err)) throw fastify.httpErrors.createError(404, `File "${req.urlData('path')}" does not exist.`)
if (isNotFoundError(err) || isVersionMismatchError(err)) throw fastify.httpErrors.createError(404, `File "${req.urlData('path')}" does not exist.`, err)
throw fastify.httpErrors.createError(err.statusCode || 500, err)
}
})
......
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