...
|
...
|
@@ -10,8 +10,6 @@ const sender = global.yoho.apmSender; |
|
|
const config = global.yoho.config;
|
|
|
const hostname = require('os').hostname();
|
|
|
const routeEncode = require('./route-encode');
|
|
|
const pathWhiteList = require('./limiter/rules/path-white-list');
|
|
|
const ipWhiteList = require('./limiter/rules/ip-white-list');
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
const replaceKey = '__refer__';
|
...
|
...
|
@@ -125,7 +123,7 @@ exports.serverError = () => { |
|
|
logger.error(err);
|
|
|
}
|
|
|
|
|
|
if (req.isApmReport && err.code !== 401) {
|
|
|
if (req.isApmReport && !err.apiError) {
|
|
|
// 上报服务端错误
|
|
|
sender.addMessage({
|
|
|
measurement: 'error-report',
|
...
|
...
|
@@ -150,7 +148,7 @@ exports.serverError = () => { |
|
|
});
|
|
|
}
|
|
|
|
|
|
if (err && err.code === 401) {
|
|
|
if (err.code === 401) {
|
|
|
logger.warn(`401 warn info:client_type=${req.query.client_type},req.user=${JSON.stringify(req.user)},req.query=${JSON.stringify(req.query)},cookies=${JSON.stringify(req.cookies)}`); // eslint-disable-line
|
|
|
|
|
|
if (req.xhr) {
|
...
|
...
|
@@ -176,48 +174,27 @@ exports.serverError = () => { |
|
|
refer: req.originalUrl
|
|
|
}));
|
|
|
}
|
|
|
} else if (err.apiRisk || err.code === 9999991 || err.code === 9999992) {
|
|
|
} else if (err.apiRisk) {
|
|
|
let remoteIp = req.yoho.clientIp;
|
|
|
|
|
|
if (!err.apiRisk && (_.includes(pathWhiteList(), req.path) || (await ipWhiteList(remoteIp)))) {
|
|
|
return _err510(req, res, 510, err);
|
|
|
}
|
|
|
|
|
|
if (remoteIp.indexOf(',') > 0) {
|
|
|
let arr = remoteIp.split(',');
|
|
|
|
|
|
remoteIp = arr[0];
|
|
|
}
|
|
|
|
|
|
let sessionLimitKey;
|
|
|
let isHuman;
|
|
|
|
|
|
if (err.apiRisk) {
|
|
|
sessionLimitKey = 'apiRiskValidate';
|
|
|
if (_.get(req.app.locals, 'wap.open.apmrisk', false)) {
|
|
|
cache.setAsync(`${config.app}:limit2:${remoteIp}`, 1, config.LIMITER_IP_TIME);
|
|
|
} else {
|
|
|
sessionLimitKey = 'apiLimitValidate';
|
|
|
isHuman = await cache.getAsync(`${config.app}:limiter:api:ishuman:${remoteIp}`);
|
|
|
cache.setAsync(`${config.app}:limiter:${remoteIp}`, 1, config.LIMITER_IP_TIME);
|
|
|
}
|
|
|
|
|
|
if (!isHuman) {
|
|
|
if (_.get(req.app.locals, 'wap.open.apmrisk', false)) {
|
|
|
cache.setAsync(`${config.app}:limit2:${remoteIp}`, 1, config.LIMITER_IP_TIME);
|
|
|
} else {
|
|
|
cache.setAsync(`${config.app}:limiter:${remoteIp}`, 1, config.LIMITER_IP_TIME);
|
|
|
}
|
|
|
|
|
|
req.session[sessionLimitKey] = true;
|
|
|
|
|
|
if (req.xhr) {
|
|
|
return res.status(510).json({
|
|
|
code: err.code,
|
|
|
data: {refer: checkRefer.replace(replaceKey, req.get('Referer') || '')}
|
|
|
});
|
|
|
}
|
|
|
req.session.apiRiskValidate = true;
|
|
|
|
|
|
return res.redirect(checkRefer.replace(replaceKey, req.protocol + '://' + req.get('host') + req.originalUrl));
|
|
|
if (req.xhr) {
|
|
|
return res.status(510).json({
|
|
|
code: err.code,
|
|
|
data: {refer: checkRefer.replace(replaceKey, req.get('Referer') || '')}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return res.redirect(checkRefer.replace(replaceKey, req.protocol + '://' + req.get('host') + req.originalUrl));
|
|
|
|
|
|
} else if (err.code === 9999991 || err.code === 9999992) {
|
|
|
return _err510(req, res, 510, err);
|
|
|
}
|
|
|
|
...
|
...
|
|