Authored by 毕凯

修改错误日志记录

... ... @@ -9,7 +9,7 @@ var express = require('express'),
exphbs = require('express-handlebars'),
bodyParser = require('body-parser');
var logger = require('morgan'),
var morgan = require('morgan'),
favicon = require('serve-favicon'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
... ... @@ -38,7 +38,7 @@ app.engine('.hbs', exphbs({
app.set('view engine', '.hbs');
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
app.use(logger('dev'));
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
... ... @@ -76,7 +76,7 @@ app.use(function(req, res) {
// 捕获全局错误, 开发环境返回错误详情
app.use(function(err, req, res) {
if (app.locals.devEnv) {
console.log(err);
console.warn(err);
} else {
err = {};
}
... ...
... ... @@ -2,17 +2,18 @@
exports.apiError = (err) => {
// TODO: 完善 API 调用错误日志格式
console.log('接口调用失败', err);
console.error('接口调用失败:', err.options.url, err.toString());
return Promise.reject(err);
};
// 控制返回到页面的错误信息
exports.webError = (err, res) => {
if (res.app.locals.devEnv) {
console.log(err);
console.warn(err);
} else {
err = {};
}
res.status(err.status || 500);
res.render('error', {
message: err.message,
... ...