xzwebx-httpfilter 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HttpFilter.js +40 -36
- package/package.json +1 -1
package/HttpFilter.js
CHANGED
|
@@ -10,11 +10,10 @@ let FieldMap = {}
|
|
|
10
10
|
let IsCheckedRes = true
|
|
11
11
|
async function response(req, res, next) {
|
|
12
12
|
let retData = {
|
|
13
|
-
codeKey: '
|
|
13
|
+
codeKey: 'SUCC',
|
|
14
14
|
data: []
|
|
15
15
|
}
|
|
16
|
-
retData
|
|
17
|
-
return res.send(res.Msg(retData, req.interfaceInfo.rspMsgId))
|
|
16
|
+
return res.Msg(retData)
|
|
18
17
|
}
|
|
19
18
|
function SetIsCheckedRes(isCheckedRes) {
|
|
20
19
|
if (isCheckedRes) {
|
|
@@ -30,50 +29,54 @@ function Init(language, resultCodeMap, tipsMap, moduleMap, moduleInterfaceMap, f
|
|
|
30
29
|
ModuleInterfaceMap = moduleInterfaceMap
|
|
31
30
|
FieldMap = fieldMap
|
|
32
31
|
}
|
|
33
|
-
function MSG(params
|
|
34
|
-
if (IsCheckedRes &&
|
|
35
|
-
|
|
32
|
+
function MSG(params) {
|
|
33
|
+
if (IsCheckedRes &&
|
|
34
|
+
this.interfaceInfo.rspMsgId &&
|
|
35
|
+
params.codeKey == 'SUCC') {
|
|
36
|
+
let retMsgData = cycleCheckParams(FieldMap[this.interfaceInfo.rspMsgId], params.data)
|
|
36
37
|
if (retMsgData) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} else {
|
|
40
|
-
let code = ''
|
|
41
|
-
if (ResultCodeMap[params.codeKey]) {
|
|
42
|
-
code = ResultCodeMap[params.codeKey].rstCode
|
|
38
|
+
params.codeKey = 'SVC_ERR'
|
|
39
|
+
params.msg = retMsgData
|
|
43
40
|
}
|
|
41
|
+
}
|
|
42
|
+
let code = ''
|
|
43
|
+
if (ResultCodeMap[params.codeKey]) {
|
|
44
|
+
code = ResultCodeMap[params.codeKey].rstCode
|
|
45
|
+
}
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} else {
|
|
50
|
-
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
51
|
-
}
|
|
47
|
+
let msg = ''
|
|
48
|
+
if (!params.msg) {
|
|
49
|
+
if (TipsMap[params.codeKey]) {
|
|
50
|
+
msg = TipsMap[params.codeKey].tips
|
|
52
51
|
} else {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
if (typeof params.msg == 'string') {
|
|
56
|
+
msg = params.msg
|
|
57
|
+
}
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
59
|
+
if (typeof params.msg == 'object' && params.msg.length) {
|
|
60
|
+
if (TipsMap[params.msg[0]]) {
|
|
61
|
+
msg = TipsMap[params.msg[0]].tips
|
|
62
|
+
if (params.msg.length > 1) {
|
|
63
|
+
for (let i = 1; i < params.msg.length; i++) {
|
|
64
|
+
msg = Util.format(msg, params.msg[i])
|
|
64
65
|
}
|
|
65
|
-
} else {
|
|
66
|
-
msg = params.msg[0]
|
|
67
66
|
}
|
|
67
|
+
} else {
|
|
68
|
+
msg = params.msg[0]
|
|
68
69
|
}
|
|
69
70
|
}
|
|
71
|
+
}
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
return this.send(
|
|
74
|
+
{
|
|
72
75
|
code: code,
|
|
73
76
|
msg: msg,
|
|
74
77
|
data: params.data
|
|
75
78
|
}
|
|
76
|
-
|
|
79
|
+
)
|
|
77
80
|
}
|
|
78
81
|
function SetRoutes(app, express, projectPath) {
|
|
79
82
|
for (let uri in ModuleMap) {
|
|
@@ -116,16 +119,17 @@ function CheckReq(req, res, next) {
|
|
|
116
119
|
|
|
117
120
|
const module = ModuleMap[baseUrl]
|
|
118
121
|
if (!module) {
|
|
119
|
-
return res.
|
|
122
|
+
return res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']})
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
if (!ModuleInterfaceMap[module.id] ||
|
|
123
126
|
!ModuleInterfaceMap[module.id][subUri] ||
|
|
124
127
|
!ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]) {
|
|
125
|
-
return res.
|
|
128
|
+
return res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']})
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
req['interfaceInfo'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
|
|
132
|
+
res['interfaceInfo'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
|
|
129
133
|
let reqMsgId = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()].reqMsgId
|
|
130
134
|
if (!reqMsgId) {
|
|
131
135
|
return next()
|
|
@@ -133,7 +137,7 @@ function CheckReq(req, res, next) {
|
|
|
133
137
|
|
|
134
138
|
let retMsgData = cycleCheckParams(FieldMap[reqMsgId], req.body)
|
|
135
139
|
if (retMsgData) {
|
|
136
|
-
return res.
|
|
140
|
+
return res.Msg({codeKey: 'CLT_ERR', msg: retMsgData})
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
return next()
|