xzwebx-httpfilter 2.0.1 → 2.2.0
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 +48 -32
- package/package.json +1 -1
package/HttpFilter.js
CHANGED
|
@@ -7,57 +7,72 @@ let TipsMap = {}
|
|
|
7
7
|
let ModuleMap = {}
|
|
8
8
|
let ModuleInterfaceMap = {}
|
|
9
9
|
let FieldMap = {}
|
|
10
|
+
let IsCheckedRes = true
|
|
10
11
|
async function response(req, res, next) {
|
|
11
12
|
let retData = {
|
|
12
13
|
codeKey: 'SVC_ERR',
|
|
13
14
|
data: []
|
|
14
15
|
}
|
|
15
16
|
retData.codeKey = 'SUCC'
|
|
16
|
-
return res.send(res.Msg(retData))
|
|
17
|
+
return res.send(res.Msg(retData, req.interfaceInfo.rspMsgId))
|
|
18
|
+
}
|
|
19
|
+
function SetIsCheckedRes(isCheckedRes) {
|
|
20
|
+
if (isCheckedRes) {
|
|
21
|
+
IsCheckedRes = true
|
|
22
|
+
} else {
|
|
23
|
+
IsCheckedRes = false
|
|
24
|
+
}
|
|
17
25
|
}
|
|
18
26
|
function Init(language, resultCodeMap, tipsMap, moduleMap, moduleInterfaceMap, fieldMap) {
|
|
19
27
|
ResultCodeMap = resultCodeMap
|
|
20
|
-
TipsMap = tipsMap[language]
|
|
28
|
+
TipsMap = tipsMap[language] || {}
|
|
21
29
|
ModuleMap = moduleMap
|
|
22
30
|
ModuleInterfaceMap = moduleInterfaceMap
|
|
23
31
|
FieldMap = fieldMap
|
|
24
32
|
}
|
|
25
|
-
function MSG(params) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let msg = ''
|
|
32
|
-
if (!params.msg) {
|
|
33
|
-
if (TipsMap[params.codeKey]) {
|
|
34
|
-
msg = TipsMap[params.codeKey].tips
|
|
35
|
-
} else {
|
|
36
|
-
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
33
|
+
function MSG(params, rspMsgId) {
|
|
34
|
+
if (IsCheckedRes && rspMsgId) {
|
|
35
|
+
let retMsgData = cycleCheckParams(FieldMap[rspMsgId], params.data)
|
|
36
|
+
if (retMsgData) {
|
|
37
|
+
return MSG({codeKey: 'CLT_ERR', msg: retMsgData, data: params.data})
|
|
37
38
|
}
|
|
38
39
|
} else {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
let code = ''
|
|
41
|
+
if (ResultCodeMap[params.codeKey]) {
|
|
42
|
+
code = ResultCodeMap[params.codeKey].rstCode
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
let msg = ''
|
|
46
|
+
if (!params.msg) {
|
|
47
|
+
if (TipsMap[params.codeKey]) {
|
|
48
|
+
msg = TipsMap[params.codeKey].tips
|
|
49
|
+
} else {
|
|
50
|
+
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
if (typeof params.msg == 'string') {
|
|
54
|
+
msg = params.msg
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof params.msg == 'object' && params.msg.length) {
|
|
58
|
+
if (TipsMap[params.msg[0]]) {
|
|
59
|
+
msg = TipsMap[params.msg[0]].tips
|
|
60
|
+
if (params.msg.length > 1) {
|
|
61
|
+
for (let i = 1; i < params.msg.length; i++) {
|
|
62
|
+
msg = Util.format(msg, params.msg[i])
|
|
63
|
+
}
|
|
49
64
|
}
|
|
65
|
+
} else {
|
|
66
|
+
msg = params.msg[0]
|
|
50
67
|
}
|
|
51
|
-
} else {
|
|
52
|
-
msg = params.msg[0]
|
|
53
68
|
}
|
|
54
69
|
}
|
|
55
|
-
}
|
|
56
70
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
return {
|
|
72
|
+
code: code,
|
|
73
|
+
msg: msg,
|
|
74
|
+
data: params.data
|
|
75
|
+
}
|
|
61
76
|
}
|
|
62
77
|
}
|
|
63
78
|
function SetRoutes(app, express, projectPath) {
|
|
@@ -110,7 +125,7 @@ function CheckReq(req, res, next) {
|
|
|
110
125
|
return res.send(res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']}))
|
|
111
126
|
}
|
|
112
127
|
|
|
113
|
-
req
|
|
128
|
+
req['interfaceInfo'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
|
|
114
129
|
let reqMsgId = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()].reqMsgId
|
|
115
130
|
if (!reqMsgId) {
|
|
116
131
|
return next()
|
|
@@ -420,7 +435,7 @@ function IsObjOk(fCfgItem, paramValue) {
|
|
|
420
435
|
return null
|
|
421
436
|
}
|
|
422
437
|
|
|
423
|
-
if (!paramValue || paramValue
|
|
438
|
+
if (!paramValue || typeof paramValue != 'object' || !Object.keys(paramValue).length || paramValue.length) {
|
|
424
439
|
if (fCfgItem.nullTips) {
|
|
425
440
|
return getCustomTips(fCfgItem.nullTips)
|
|
426
441
|
}
|
|
@@ -470,7 +485,7 @@ function IsListOk(fCfgItem, paramValue) {
|
|
|
470
485
|
return null
|
|
471
486
|
}
|
|
472
487
|
|
|
473
|
-
if (!paramValue || paramValue
|
|
488
|
+
if (!paramValue || typeof paramValue != 'object' || !paramValue.length) {
|
|
474
489
|
if (fCfgItem.nullTips) {
|
|
475
490
|
return getCustomTips(fCfgItem.nullTips)
|
|
476
491
|
}
|
|
@@ -516,4 +531,5 @@ module.exports = {
|
|
|
516
531
|
SetRoutes: SetRoutes,
|
|
517
532
|
CheckReq: CheckReq,
|
|
518
533
|
SetMsg: SetMsg,
|
|
534
|
+
SetIsCheckedRes: SetIsCheckedRes
|
|
519
535
|
}
|