error-handler.js 498 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}`);

  if (req.xhr) {
    return res.json({
      code: err.code || 500,
      message: err.message || '服务器错误!'
    });
  }

  res.status(err.code || 500);

  return res.send('服务器开小差了~');
};