error.js
806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* error处理
* @author: leo<qi.li@yoho.cn>
* @date: 2017/06/23
*/
const logger = global.yoho.logger;
const serverError = (err, req, res, next) => { // eslint-disable-line
logger.error(err);
if (err.code === 401) {
return res.status(401).json({
code: 401,
message: '抱歉,您暂未登录!'
});
}
if (err.code === 404) {
return res.status(404).json({
code: 404,
message: 'Not Found'
});
}
return res.status(500).json({
code: 500,
message: '服务器错误!'
});
};
const notFound = (req, res) => {
res.status(404);
return res.json({
code: 404,
message: '请求路径不存在'
});
};
module.exports = {
notFound,
serverError
};