mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-15 09:05:58 +00:00
25 lines
696 B
JavaScript
25 lines
696 B
JavaScript
|
|
const Error = require('egads').extend('Server Error', 500, 'Generic Server Error');
|
|
|
|
Error.noBrew = Error.extend('Can not find a brew with that id', 404, 'No Brew Found');
|
|
Error.noAuth = Error.extend('You can not access this route', 401, 'Unauthorized');
|
|
Error.noAdmin = Error.extend('You need admin credentials to access this route', 401, 'Unauthorized');
|
|
|
|
|
|
Error.expressHandler = (err, req, res, next) => {
|
|
if(err instanceof Error){
|
|
return res.status(err.status).send({
|
|
type : err.name,
|
|
message : err.message
|
|
});
|
|
}
|
|
//If server error, print the whole stack for debugging
|
|
return res.status(500).send({
|
|
message : err.message,
|
|
stack : err.stack
|
|
});
|
|
};
|
|
|
|
|
|
|
|
module.exports = Error; |