Commit 584b26727b8a09f33897236e8eac17dcc719a642

Authored by Nattapon Wongpaet
1 parent 93fce284
Exists in master and in 1 other branch dev

update handler error timeout reject

ais-structure/src/modules/customer/customer.ctrl.js
... ... @@ -8,7 +8,6 @@ var constant = require('../helper/constants.js')
8 8 exports.customer = async function (req, res, next) {
9 9 var getCmd = "Customer";
10 10 var sendCmd = "Customer";
11   - var sacf = "SACF";
12 11 var d01 = "D01"
13 12 var method = constant.METHOD.GET
14 13  
... ... @@ -27,13 +26,13 @@ exports.customer = async function (req, res, next) {
27 26  
28 27 if(err.length > 0)
29 28 {
30   - log.addErrorSummary(req.query.clientName,method+"_"+getCmd,"null","Fail");
  29 + log.addErrorSummary(req.query.clientName,method+"_"+getCmd,"null",constant.FAIL);
31 30 log.log(err,'error');
32 31 var response = responseMsg.error(req,getCmd,40300);
33 32 // res.status(200).json(response);
34 33 }else
35 34 {
36   - log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null","Success");
  35 + log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null",constant.SUCCESS);
37 36 var objectData = req.query;
38 37 const result = await connection.requestJsonToD01(objectData,sendCmd,method);
39 38 // console.log(Object.keys(result))
... ... @@ -41,26 +40,31 @@ exports.customer = async function (req, res, next) {
41 40 if(typeof result.err === 'undefined'){
42 41 // console.log(result.response);
43 42 var resultObj = result.response;
44   - if(resultObj.resultCode == "20000")
  43 + if(resultObj.resultCode.startsWith("2"))
45 44 {
46 45 if(resultObj.resultData && resultObj.resultData.length>0)
47 46 {
48   - stats.receiveRestResponse(d01,method,sendCmd,"Success");
  47 + stats.receiveRestResponse(d01,method,sendCmd,constant.SUCCESS);
49 48 var response = responseMsg.success(req,getCmd,resultObj);
50 49 log.addSuccessSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage);
51 50 }else
52 51 {
53   - stats.receiveRestResponse(d01,method,sendCmd,"Data Not Found");
  52 + stats.receiveRestResponse(d01,method,sendCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage);
54 53 var response = responseMsg.error(req,getCmd,40300);
55 54 log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage);
56 55 }
  56 + } else {
  57 + stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR);
  58 + var response = responseMsg.direct(req,getCmd,resultObj);
  59 + log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage);
57 60 }
58 61 } else {
59   - var response = responseMsg.direct(req,getCmd,result.response);
60   - log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage);
  62 + stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR);
  63 + var response = responseMsg.error(req,getCmd,50000);
  64 + // log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage);
61 65 }
62 66 }
63   -
  67 +
64 68 log.logDetail.addOutput(req.query.clientName,method+"_"+getCmd,constant.RESPONSE,response,response);
65 69 res.status(200).json(response);
66 70 next();
... ...
ais-structure/src/modules/customer/postCustomer.ctrl.js
... ... @@ -8,7 +8,6 @@ var constant = require('../helper/constants.js')
8 8 exports.postCustomer = async function (req, res, next){
9 9 var getCmd = "Customer";
10 10 var sendCmd = "Customer";
11   - var sacf = "SACF";
12 11 var d01 = "D01";
13 12 var method = constant.METHOD.POST;
14 13  
... ... @@ -23,12 +22,12 @@ exports.postCustomer = async function (req, res, next){
23 22  
24 23 if(err.length > 0)
25 24 {
26   - log.addErrorSummary(req.query.clientName,method+"_"+getCmd,"null","Fail");
  25 + log.addErrorSummary(req.body.clientName,method+"_"+getCmd,"null",constant.FAIL);
27 26 console.log(err);
28 27 var response = responseMsg.error(req,getCmd,40300);
29 28 }else
30 29 {
31   - log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null","Success");
  30 + log.addSuccessSummary(req.body.clientName,method+"_"+getCmd,"null",constant.SUCCESS);
32 31 var objectData = {
33 32 customerId : customerId,
34 33 userIdData : req.body.user.userData,
... ... @@ -40,28 +39,28 @@ exports.postCustomer = async function (req, res, next){
40 39 dateCreated : req.body.dateCreated
41 40 };
42 41  
43   - const result = await connection.requestJsonToD01(objectData,sendCmd,"POST");
  42 + const result = await connection.requestJsonToD01(objectData,sendCmd,method);
44 43 log.logDetail.addInput(d01,method+"_"+sendCmd,constant.RESPONSE,result,result.response);
45 44 if(typeof result.err === 'undefined'){
46 45 // console.log(result.response.body);
47 46 var resultObj = result.response;
48 47 if(resultObj.resultCode.startsWith("2"))
49 48 {
50   - stats.receiveRestResponse(d01,constant.METHOD.POST,sendCmd,"Success");
  49 + stats.receiveRestResponse(d01,method,sendCmd,constant.SUCCESS);
51 50 var response = responseMsg.direct(req,getCmd,resultObj,{customerId:objectData.customerId});
52 51 log.addSuccessSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage);
53 52 } else {
54   - if(resultObj.resultCode != "40401"){
55   - resultObj.resultCode = "50000";
  53 + if(resultObj.resultCode != constant.RESPONSERESULT.DATA_NOT_FOUND.resultCode){
  54 + resultObj.resultCode = constant.RESPONSERESULT.ERROR.resultCode;
56 55 }
57   - stats.receiveRestResponse(d01,constant.METHOD.POST,sendCmd,"Error");
  56 + stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR);
58 57 var response = responseMsg.direct(req,getCmd,resultObj);
59 58 log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage);
60 59 }
61 60 } else {
62   - stats.receiveRestResponse(d01,constant.METHOD.POST,sendCmd,"Error");
63   - var response = responseMsg.direct(req,getCmd,result.response);
64   - log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage);
  61 + stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR);
  62 + var response = responseMsg.error(req,getCmd,50000);
  63 + // log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage);
65 64 }
66 65 }
67 66  
... ...
ais-structure/src/modules/helper/connection.js
... ... @@ -64,7 +64,7 @@ connection.requestSoapToSACF = async function (soap,cmd,myMethod) {
64 64 // stats.receiveResponse(service.Name,cmd,constants.ERROR);
65 65 // }
66 66  
67   - return checkResponse(result,service,params,cmd);
  67 + return checkResponse(result,funStats);
68 68 };
69 69  
70 70 connection.requestJsonToD01 = async function (obj,cmd,myMethod) {
... ... @@ -94,7 +94,7 @@ connection.requestJsonToD01 = async function (obj,cmd,myMethod) {
94 94  
95 95 var funStats = {
96 96 start : funStats,
97   - error : function(response){log.addErrorSummary(service.Name,myMethod+"_"+cmd,response);}
  97 + error : function(response){log.addErrorSummary(service.Name,myMethod+"_"+cmd,response.resultCode,response.resultDescription);}
98 98 };
99 99  
100 100  
... ... @@ -201,7 +201,7 @@ connection.requestJsonToD01 = async function (obj,cmd,myMethod) {
201 201 }
202 202 }
203 203  
204   - return checkResponse(result,service,params,cmd);
  204 + return checkResponse(result,funStats);
205 205 };
206 206  
207 207  
... ... @@ -247,11 +247,15 @@ function asyncRequest (params = {},objectData,funStat) {
247 247 {
248 248 var errRes = {};
249 249 if(error.code == 'ETIMEDOUT'){
250   - errRes.resultCode = "50003";
251   - errRes.resultDescription = "Timeout";
  250 + // errRes.resultCode = "50003";
  251 + // errRes.resultDescription = "Timeout";
  252 + errRes.resultCode = "50000";
  253 + errRes.resultDescription = "System error";
252 254 } else if(error.code == 'ECONNREFUSED'){
253   - errRes.resultCode = "50002";
254   - errRes.resultDescription = "Reject";
  255 + // errRes.resultCode = "50002";
  256 + // errRes.resultDescription = "Reject";
  257 + errRes.resultCode = "50000";
  258 + errRes.resultDescription = "System error";
255 259 } else {
256 260 errRes.resultCode = "50000";
257 261 errRes.resultDescription = "System error";
... ... @@ -462,7 +466,7 @@ function arrayUrl(arrUrl,url,filter,fields,freeSpace,arrData)
462 466 return arrUrl;
463 467 }
464 468  
465   -function checkResponse(result,service,params,cmd)
  469 +function checkResponse(result,funStats)
466 470 {
467 471 if(result.err)
468 472 {
... ... @@ -483,15 +487,10 @@ function checkResponse(result,service,params,cmd)
483 487 result.response = constants.RESPONSECONN.MESSAGE.ERROR;
484 488 }
485 489 }
486   -
487   - if(result.response.resultCode == constants.RESPONSERESULT.MISSING_INVALID.resultCode){
488   - stats.receiveBadRestResponse(service.Name,params.method,cmd);
489   - } else {
490   - stats.receiveResponse(service.Name,cmd,constants.ERROR);
491   - }
492   -
493 490 }
494 491  
  492 + funStats.error(result.response)
  493 +
495 494 return result;
496 495 }
497 496  
... ...
ais-structure/src/modules/helper/constants.js
... ... @@ -3,6 +3,7 @@ module.exports = Object.freeze({
3 3 RESPONSE: 'Response',
4 4 SUCCESS: 'Success',
5 5 ERROR: 'Error',
  6 + FAIL: 'Fail',
6 7 METHOD:{
7 8 GET : 'GET',
8 9 POST : 'POST',
... ...
ais-structure/src/modules/vizcard/vizCard.ctrl.js
... ... @@ -71,7 +71,7 @@ exports.vizcard = async function (req, res, next) {
71 71 } else {
72 72 stats.receiveSACFResponse(sacf,sendCmd,"Error");
73 73 response = responseMsg.direct(req,getCmd,result.response);
74   - log.addErrorSummary(sacf,method+"_"+sendCmd,response.resultCode,response.developerMessage);
  74 + // log.addErrorSummary(sacf,method+"_"+sendCmd,response.resultCode,response.developerMessage);
75 75 var resultSet = {rawDataJson : ""}
76 76 }
77 77  
... ...