Skip to content

Commit

Permalink
bug-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrandshema committed May 15, 2024
1 parent 0be6208 commit 284b448
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/middlewares/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,10 @@ type MiddlewareFunction = (req: Request, res: Response) => Promise<Response<Reco
function errorHandler(func: MiddlewareFunction): MiddlewareFunction {
return async (req: Request, res: Response) => {
try {
<<<<<<< HEAD
return await func(req, res);
} catch (error) {
const message = (error as { detail?: string }).detail || 'Internal Server Error';
return res.status(500).send(message);
=======
await func(req, res, next);
} catch (error) {
// Check if the error is an instance of Error
if (error instanceof Error) {
// Check if the error is related to token verification failure
if (error.name === 'TokenExpiredError' || error.name === 'JsonWebTokenError') {
return res.status(404).json({ message: 'Invalid or expired token' });
}
}
// If it's not a token verification error or not an instance of Error, handle other errors with a 500 response
return res.status(500).json({ message: 'Internal Server Error' });
>>>>>>> 60db8552cfa192cd75df91196e06ca2d5700bfa8
}
};
}
Expand Down

0 comments on commit 284b448

Please sign in to comment.