|
|
|
@ -21,11 +21,20 @@ const RouterApi = Router();
|
|
|
|
|
*/
|
|
|
|
|
const errorHandler = (res: Response, err: Error | any) => {
|
|
|
|
|
log.error(err);
|
|
|
|
|
|
|
|
|
|
// Get the status code for the Response
|
|
|
|
|
let code: number;
|
|
|
|
|
switch (err.message) {
|
|
|
|
|
case 'User not found': return res.sendStatus(404);
|
|
|
|
|
case 'Meta key already exists': return res.sendStatus(409);
|
|
|
|
|
default: return res.sendStatus(500);
|
|
|
|
|
case 'User not found':
|
|
|
|
|
code = 404; break;
|
|
|
|
|
case 'Meta key already exists':
|
|
|
|
|
case 'Username already taken':
|
|
|
|
|
code = 409; break;
|
|
|
|
|
default:
|
|
|
|
|
code = 500;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res.status(code).type('text').send(err.message ?? err);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|