Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use((err, req, res, next) => {
if (err && isCelebrate(err)) {
logger.error('validation.failed', { err, method: req.method, path: req.url });
}
defaultErrorHandler(err, req, res, next);
// capture validation errors
raven.ravenModule.captureException(err);
});
};
export const errorHandle = (error, req, res, next) => {
if (typeof error === 'string') {
// custom application error
return Response.error(res, { message: error });
} else if (isCelebrate(error)) {
logger.error('isCelebrate %s', isCelebrate(error));
const { joi } = error;
return Response.error(res, {
message: 'Invalid request data. Please review request and try again.',
code: joi.name,
errors: joi.details.map(({ message, type }) => ({
message: message.replace(/['"]/g, ''),
type
}))
});
} else if (error.name === 'CastError' && error.kind === 'ObjectId') {
return Response.error(res, {
// code: error.name,
message: 'malformatted id'
});
} else if (error.name === 'ValidationError') {
export const errorHandle = (error, req, res, next) => {
if (typeof error === 'string') {
// custom application error
return Response.error(res, { message: error });
} else if (isCelebrate(error)) {
logger.error('isCelebrate %s', isCelebrate(error));
const { joi } = error;
return Response.error(res, {
message: 'Invalid request data. Please review request and try again.',
code: joi.name,
errors: joi.details.map(({ message, type }) => ({
message: message.replace(/['"]/g, ''),
type
}))
});
} else if (error.name === 'CastError' && error.kind === 'ObjectId') {
return Response.error(res, {
// code: error.name,
message: 'malformatted id'
});
} else if (error.name === 'ValidationError') {
return Response.error(res, {