error-handler.js
471 Bytes
const logger = global.yoho.logger;
/**
* 服务器错误
* @return {[type]}
*/
exports.serverError = (err, req, res, next) => { // eslint-disable-line
logger.error(`error at path: ${req.url}`);
logger.error(`${req.url},${typeof err === 'object' ? JSON.stringify(err) : err}`);
res.status(err.code || 500);
if (req.xhr) {
return res.json({
code: 500,
message: '服务器错误!'
});
}
return res.send('服务器开小差了~');
};