mirror of
https://github.com/ThisIsBenny/wishlist-app.git
synced 2025-06-07 05:57:41 +00:00
#1 not found handling improved
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
abf6addb70
commit
ff4a891b35
3 changed files with 9 additions and 4 deletions
|
@ -10,6 +10,10 @@ class httpError extends Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const notFoundError = () => {
|
||||||
|
return new httpError('Not Found', 404, '404')
|
||||||
|
}
|
||||||
|
|
||||||
export const uniqueKeyError = (msg: string, code = '4001') => {
|
export const uniqueKeyError = (msg: string, code = '4001') => {
|
||||||
return new httpError(msg, 422, code)
|
return new httpError(msg, 422, code)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
import { FastifyInstance } from 'fastify'
|
import { FastifyInstance } from 'fastify'
|
||||||
import { default as wishlistRoute } from './wishlist/'
|
import { default as wishlistRoute } from './wishlist/'
|
||||||
|
import { notFoundError } from '../config/errors'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
register: (app: FastifyInstance) => {
|
register: (app: FastifyInstance) => {
|
||||||
return app.register(
|
return app.register(
|
||||||
async (app) => {
|
async (app) => {
|
||||||
|
app.setNotFoundHandler((request, reply) => {
|
||||||
|
reply.send(notFoundError())
|
||||||
|
})
|
||||||
await app.register(wishlistRoute, { prefix: '/wishlist' })
|
await app.register(wishlistRoute, { prefix: '/wishlist' })
|
||||||
},
|
},
|
||||||
{ prefix: '/api' }
|
{ prefix: '/api' }
|
||||||
|
|
|
@ -68,10 +68,7 @@ export const getBySlugUrl = <RouteOptions>{
|
||||||
if (list) {
|
if (list) {
|
||||||
return list
|
return list
|
||||||
} else {
|
} else {
|
||||||
return reply.code(404).send({
|
return reply.callNotFound()
|
||||||
error: 'notFound',
|
|
||||||
http: 404,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue