mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2025-12-19 05:47:46 +00:00
major merge of features from the hosted branch that was created temporarily during the initial launch of jambonz.org
25 lines
836 B
JavaScript
25 lines
836 B
JavaScript
const {DbErrorBadRequest, DbErrorUnprocessableRequest, DbErrorForbidden} = require('../utils/errors');
|
|
|
|
function sysError(logger, res, err) {
|
|
if (err instanceof DbErrorBadRequest) {
|
|
logger.info(err, 'invalid client request');
|
|
return res.status(400).json({msg: err.message});
|
|
}
|
|
if (err instanceof DbErrorUnprocessableRequest) {
|
|
logger.info(err, 'unprocessable request');
|
|
return res.status(422).json({msg: err.message});
|
|
}
|
|
if (err instanceof DbErrorForbidden) {
|
|
logger.info(err, 'forbidden');
|
|
return res.status(403).json({msg: err.message});
|
|
}
|
|
if (err.code === 'ER_DUP_ENTRY') {
|
|
logger.info(err, 'duplicate entry on insert');
|
|
return res.status(422).json({msg: err.message});
|
|
}
|
|
logger.error(err, 'Database error');
|
|
res.status(500).json({msg: err.message});
|
|
}
|
|
|
|
module.exports = sysError;
|