#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>{
}, },
}, },
}, },
errorHandler: (error, request, reply) => {
if (error instanceof prisma.errorType && error.code === 'P2002') {
return reply.send(uniqueKeyError('Slugtext has to be unique'))
}
request.log.error(error)
reply.send(new Error('Unexptected Error'))
},
handler: async (request: GetBySlugUrlTextRequest, reply: FastifyReply) => { handler: async (request: GetBySlugUrlTextRequest, reply: FastifyReply) => {
request.log.debug(request.body) request.log.debug(request.body)
try { const item = await wishlist.create(request.body as Wishlist)
const item = await wishlist.create(request.body as Wishlist) return item
return item
} catch (error) {
if (error instanceof prisma.errorType && error.code === 'P2002') {
return reply.send(uniqueKeyError('Slugtext has to be unique'))
}
request.log.error(error)
throw new Error('Unexptected Error')
}
}, },
} }