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