xzwebx-httpfilter 2.0.1 → 2.1.8

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.
Files changed (2) hide show
  1. package/HttpFilter.js +52 -31
  2. 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.GetRspMsgId()))
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
- let code = ''
27
- if (ResultCodeMap[params.codeKey]) {
28
- code = ResultCodeMap[params.codeKey].rstCode
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
- if (typeof params.msg == 'string') {
40
- msg = params.msg
40
+ let code = ''
41
+ if (ResultCodeMap[params.codeKey]) {
42
+ code = ResultCodeMap[params.codeKey].rstCode
41
43
  }
42
44
 
43
- if (typeof params.msg == 'object' && params.msg.length) {
44
- if (TipsMap[params.msg[0]]) {
45
- msg = TipsMap[params.msg[0]].tips
46
- if (params.msg.length > 1) {
47
- for (let i = 1; i < params.msg.length; i++) {
48
- msg = Util.format(msg, params.msg[i])
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
- return {
58
- code: code,
59
- msg: msg,
60
- data: params.data
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,6 +125,11 @@ function CheckReq(req, res, next) {
110
125
  return res.send(res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']}))
111
126
  }
112
127
 
128
+ req['__rspMsgId'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()].rspMsgId || ''
129
+ req['GetRspMsgId'] = function() {
130
+ return req['__rspMsgId']
131
+ }
132
+
113
133
  req.headers['interfaceInfo'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
114
134
  let reqMsgId = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()].reqMsgId
115
135
  if (!reqMsgId) {
@@ -420,7 +440,7 @@ function IsObjOk(fCfgItem, paramValue) {
420
440
  return null
421
441
  }
422
442
 
423
- if (!paramValue || paramValue.constructor != Object || !Object.keys(paramValue).length) {
443
+ if (!paramValue || typeof paramValue != 'object' || !Object.keys(paramValue).length || paramValue.length) {
424
444
  if (fCfgItem.nullTips) {
425
445
  return getCustomTips(fCfgItem.nullTips)
426
446
  }
@@ -470,7 +490,7 @@ function IsListOk(fCfgItem, paramValue) {
470
490
  return null
471
491
  }
472
492
 
473
- if (!paramValue || paramValue.constructor != Array || !paramValue.length) {
493
+ if (!paramValue || typeof paramValue != 'object' || !paramValue.length) {
474
494
  if (fCfgItem.nullTips) {
475
495
  return getCustomTips(fCfgItem.nullTips)
476
496
  }
@@ -516,4 +536,5 @@ module.exports = {
516
536
  SetRoutes: SetRoutes,
517
537
  CheckReq: CheckReq,
518
538
  SetMsg: SetMsg,
539
+ SetIsCheckedRes: SetIsCheckedRes
519
540
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xzwebx-httpfilter",
3
- "version": "2.0.1",
3
+ "version": "2.1.8",
4
4
  "main": "HttpFilter.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"