Authored by xuqi
... ... @@ -40,10 +40,11 @@ app.use('/', require('./router'));
// res.send(404, err);
// });
// 捕获全局错误, 非开发环境不返回错误详情
// 捕获全局错误, 开发环境返回错误详情
app.use(function(err, req, res) {
if (app.get('env') !== 'development') {
if (app.get('env') === 'development') {
console.log(err);
} else {
err = {};
}
res.status(err.status || 500);
... ...
... ... @@ -10,6 +10,7 @@ var errUtil = require('../util/error');
const API_URL = 'http://testapi.yoho.cn:28078';
// 最好有后端提供的各接口对应什么服务器说明,接口文档
// const DEV_API_URL = 'http://devapi.yoho.cn:58078';
// const SERVICE_URL = 'http://testservice.yoho.cn:28077';
// const YOHOBUY_URL = 'http://www.yohobuy.com';
... ... @@ -21,6 +22,8 @@ class API {
'User-Agent': 'YOHO WEB NODE' // TODO: 请求的服务端是否有要求格式,是否添加
};
this.timeout = 5000;
// TODO: 后端接口是否需求签名校验未知,如果需要需要添加
}
get(url, data) {
... ...
... ... @@ -12,6 +12,6 @@ module.exports = (data) => {
// 处理完成后,发给后端
data = Object.assign({}, data);
// 数据返回一个 Promise
// 所有数据返回一个 Promise,方便 Promise.all 调用
return api.get('/wx', data);
};
... ...
... ... @@ -12,7 +12,7 @@ exports.index = (req, res) => {
// 传入参数给lotteryModel发送到后端,获取返回的数据
lotteryModel({test: 1}).then((data) => {
// 接接口返回到的数据,处理后,渲染页面或者返回 JSON
// 接接口返回到的数据,处理后,渲染页面或者返回 JSON
res.send(data);
// res.render('wxLottery/index', {
... ... @@ -20,6 +20,6 @@ exports.index = (req, res) => {
// wxLottery: data
// });
}).catch((err) => {
errUtil.webError(err, res);
errUtil.webError(err, res); // 抓取 Promise 链的错误
});
};
... ...
... ... @@ -10,6 +10,7 @@ exports.apiError = (err) => {
exports.webError = (err, res) => {
if (res.locals.isDevelop) {
console.log(err);
} else {
err = {};
}
res.status(err.status || 500);
... ...
# 默认错误页面
默认错误页面
... ...