mirror of
https://github.com/ThisIsBenny/wishlist-app.git
synced 2025-06-07 05:57:41 +00:00
#1 error handling improved
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
ff4a891b35
commit
4b553830b0
1 changed files with 9 additions and 10 deletions
|
@ -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) => {
|
||||
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') {
|
||||
return reply.send(uniqueKeyError('Slugtext has to be unique'))
|
||||
}
|
||||
request.log.error(error)
|
||||
throw new Error('Unexptected Error')
|
||||
}
|
||||
const item = await wishlist.create(request.body as Wishlist)
|
||||
return item
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue