#1 error handling improved

Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
Benny Samir Hierl 2022-02-05 13:14:12 +01:00
parent ff4a891b35
commit 4b553830b0

View file

@ -39,17 +39,16 @@ export const createList = <RouteOptions>{
}, },
}, },
}, },
handler: async (request: GetBySlugUrlTextRequest, reply: FastifyReply) => { errorHandler: (error, request, reply) => {
request.log.debug(request.body)
try {
const item = await wishlist.create(request.body as Wishlist)
return item
} catch (error) {
if (error instanceof prisma.errorType && error.code === 'P2002') { if (error instanceof prisma.errorType && error.code === 'P2002') {
return reply.send(uniqueKeyError('Slugtext has to be unique')) return reply.send(uniqueKeyError('Slugtext has to be unique'))
} }
request.log.error(error) request.log.error(error)
throw new Error('Unexptected Error') reply.send(new Error('Unexptected Error'))
} },
handler: async (request: GetBySlugUrlTextRequest, reply: FastifyReply) => {
request.log.debug(request.body)
const item = await wishlist.create(request.body as Wishlist)
return item
}, },
} }