From 584b26727b8a09f33897236e8eac17dcc719a642 Mon Sep 17 00:00:00 2001 From: Nattapon Wongpaet Date: Thu, 23 Aug 2018 17:58:34 +0700 Subject: [PATCH] update handler error timeout reject --- ais-structure/src/modules/customer/customer.ctrl.js | 22 +++++++++++++--------- ais-structure/src/modules/customer/postCustomer.ctrl.js | 21 ++++++++++----------- ais-structure/src/modules/helper/connection.js | 29 ++++++++++++++--------------- ais-structure/src/modules/helper/constants.js | 1 + ais-structure/src/modules/vizcard/vizCard.ctrl.js | 2 +- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/ais-structure/src/modules/customer/customer.ctrl.js b/ais-structure/src/modules/customer/customer.ctrl.js index 921b1a9..0097f3d 100644 --- a/ais-structure/src/modules/customer/customer.ctrl.js +++ b/ais-structure/src/modules/customer/customer.ctrl.js @@ -8,7 +8,6 @@ var constant = require('../helper/constants.js') exports.customer = async function (req, res, next) { var getCmd = "Customer"; var sendCmd = "Customer"; - var sacf = "SACF"; var d01 = "D01" var method = constant.METHOD.GET @@ -27,13 +26,13 @@ exports.customer = async function (req, res, next) { if(err.length > 0) { - log.addErrorSummary(req.query.clientName,method+"_"+getCmd,"null","Fail"); + log.addErrorSummary(req.query.clientName,method+"_"+getCmd,"null",constant.FAIL); log.log(err,'error'); var response = responseMsg.error(req,getCmd,40300); // res.status(200).json(response); }else { - log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null","Success"); + log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null",constant.SUCCESS); var objectData = req.query; const result = await connection.requestJsonToD01(objectData,sendCmd,method); // console.log(Object.keys(result)) @@ -41,26 +40,31 @@ exports.customer = async function (req, res, next) { if(typeof result.err === 'undefined'){ // console.log(result.response); var resultObj = result.response; - if(resultObj.resultCode == "20000") + if(resultObj.resultCode.startsWith("2")) { if(resultObj.resultData && resultObj.resultData.length>0) { - stats.receiveRestResponse(d01,method,sendCmd,"Success"); + stats.receiveRestResponse(d01,method,sendCmd,constant.SUCCESS); var response = responseMsg.success(req,getCmd,resultObj); log.addSuccessSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); }else { - stats.receiveRestResponse(d01,method,sendCmd,"Data Not Found"); + stats.receiveRestResponse(d01,method,sendCmd,constant.RESPONSERESULT.DATA_NOT_FOUND.developerMessage); var response = responseMsg.error(req,getCmd,40300); log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); } + } else { + stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); + var response = responseMsg.direct(req,getCmd,resultObj); + log.addErrorSummary(d01,method+"_"+sendCmd,resultObj.resultCode,resultObj.developerMessage); } } else { - var response = responseMsg.direct(req,getCmd,result.response); - log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); + stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); + var response = responseMsg.error(req,getCmd,50000); + // log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); } } - + log.logDetail.addOutput(req.query.clientName,method+"_"+getCmd,constant.RESPONSE,response,response); res.status(200).json(response); next(); diff --git a/ais-structure/src/modules/customer/postCustomer.ctrl.js b/ais-structure/src/modules/customer/postCustomer.ctrl.js index 7a027b3..cc153ef 100644 --- a/ais-structure/src/modules/customer/postCustomer.ctrl.js +++ b/ais-structure/src/modules/customer/postCustomer.ctrl.js @@ -8,7 +8,6 @@ var constant = require('../helper/constants.js') exports.postCustomer = async function (req, res, next){ var getCmd = "Customer"; var sendCmd = "Customer"; - var sacf = "SACF"; var d01 = "D01"; var method = constant.METHOD.POST; @@ -23,12 +22,12 @@ exports.postCustomer = async function (req, res, next){ if(err.length > 0) { - log.addErrorSummary(req.query.clientName,method+"_"+getCmd,"null","Fail"); + log.addErrorSummary(req.body.clientName,method+"_"+getCmd,"null",constant.FAIL); console.log(err); var response = responseMsg.error(req,getCmd,40300); }else { - log.addSuccessSummary(req.query.clientName,method+"_"+getCmd,"null","Success"); + log.addSuccessSummary(req.body.clientName,method+"_"+getCmd,"null",constant.SUCCESS); var objectData = { customerId : customerId, userIdData : req.body.user.userData, @@ -40,28 +39,28 @@ exports.postCustomer = async function (req, res, next){ dateCreated : req.body.dateCreated }; - const result = await connection.requestJsonToD01(objectData,sendCmd,"POST"); + const result = await connection.requestJsonToD01(objectData,sendCmd,method); log.logDetail.addInput(d01,method+"_"+sendCmd,constant.RESPONSE,result,result.response); if(typeof result.err === 'undefined'){ // console.log(result.response.body); var resultObj = result.response; if(resultObj.resultCode.startsWith("2")) { - stats.receiveRestResponse(d01,constant.METHOD.POST,sendCmd,"Success"); + stats.receiveRestResponse(d01,method,sendCmd,constant.SUCCESS); var response = responseMsg.direct(req,getCmd,resultObj,{customerId:objectData.customerId}); log.addSuccessSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); } else { - if(resultObj.resultCode != "40401"){ - resultObj.resultCode = "50000"; + if(resultObj.resultCode != constant.RESPONSERESULT.DATA_NOT_FOUND.resultCode){ + resultObj.resultCode = constant.RESPONSERESULT.ERROR.resultCode; } - stats.receiveRestResponse(d01,constant.METHOD.POST,sendCmd,"Error"); + stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); var response = responseMsg.direct(req,getCmd,resultObj); log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); } } else { - stats.receiveRestResponse(d01,constant.METHOD.POST,sendCmd,"Error"); - var response = responseMsg.direct(req,getCmd,result.response); - log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); + stats.receiveRestResponse(d01,method,sendCmd,constant.ERROR); + var response = responseMsg.error(req,getCmd,50000); + // log.addErrorSummary(d01,method+"_"+sendCmd,response.resultCode,response.developerMessage); } } diff --git a/ais-structure/src/modules/helper/connection.js b/ais-structure/src/modules/helper/connection.js index 051a332..1b75bdd 100644 --- a/ais-structure/src/modules/helper/connection.js +++ b/ais-structure/src/modules/helper/connection.js @@ -64,7 +64,7 @@ connection.requestSoapToSACF = async function (soap,cmd,myMethod) { // stats.receiveResponse(service.Name,cmd,constants.ERROR); // } - return checkResponse(result,service,params,cmd); + return checkResponse(result,funStats); }; connection.requestJsonToD01 = async function (obj,cmd,myMethod) { @@ -94,7 +94,7 @@ connection.requestJsonToD01 = async function (obj,cmd,myMethod) { var funStats = { start : funStats, - error : function(response){log.addErrorSummary(service.Name,myMethod+"_"+cmd,response);} + error : function(response){log.addErrorSummary(service.Name,myMethod+"_"+cmd,response.resultCode,response.resultDescription);} }; @@ -201,7 +201,7 @@ connection.requestJsonToD01 = async function (obj,cmd,myMethod) { } } - return checkResponse(result,service,params,cmd); + return checkResponse(result,funStats); }; @@ -247,11 +247,15 @@ function asyncRequest (params = {},objectData,funStat) { { var errRes = {}; if(error.code == 'ETIMEDOUT'){ - errRes.resultCode = "50003"; - errRes.resultDescription = "Timeout"; + // errRes.resultCode = "50003"; + // errRes.resultDescription = "Timeout"; + errRes.resultCode = "50000"; + errRes.resultDescription = "System error"; } else if(error.code == 'ECONNREFUSED'){ - errRes.resultCode = "50002"; - errRes.resultDescription = "Reject"; + // errRes.resultCode = "50002"; + // errRes.resultDescription = "Reject"; + errRes.resultCode = "50000"; + errRes.resultDescription = "System error"; } else { errRes.resultCode = "50000"; errRes.resultDescription = "System error"; @@ -462,7 +466,7 @@ function arrayUrl(arrUrl,url,filter,fields,freeSpace,arrData) return arrUrl; } -function checkResponse(result,service,params,cmd) +function checkResponse(result,funStats) { if(result.err) { @@ -483,15 +487,10 @@ function checkResponse(result,service,params,cmd) result.response = constants.RESPONSECONN.MESSAGE.ERROR; } } - - if(result.response.resultCode == constants.RESPONSERESULT.MISSING_INVALID.resultCode){ - stats.receiveBadRestResponse(service.Name,params.method,cmd); - } else { - stats.receiveResponse(service.Name,cmd,constants.ERROR); - } - } + funStats.error(result.response) + return result; } diff --git a/ais-structure/src/modules/helper/constants.js b/ais-structure/src/modules/helper/constants.js index b41c329..370285c 100644 --- a/ais-structure/src/modules/helper/constants.js +++ b/ais-structure/src/modules/helper/constants.js @@ -3,6 +3,7 @@ module.exports = Object.freeze({ RESPONSE: 'Response', SUCCESS: 'Success', ERROR: 'Error', + FAIL: 'Fail', METHOD:{ GET : 'GET', POST : 'POST', diff --git a/ais-structure/src/modules/vizcard/vizCard.ctrl.js b/ais-structure/src/modules/vizcard/vizCard.ctrl.js index 241fd13..415b007 100644 --- a/ais-structure/src/modules/vizcard/vizCard.ctrl.js +++ b/ais-structure/src/modules/vizcard/vizCard.ctrl.js @@ -71,7 +71,7 @@ exports.vizcard = async function (req, res, next) { } else { stats.receiveSACFResponse(sacf,sendCmd,"Error"); response = responseMsg.direct(req,getCmd,result.response); - log.addErrorSummary(sacf,method+"_"+sendCmd,response.resultCode,response.developerMessage); + // log.addErrorSummary(sacf,method+"_"+sendCmd,response.resultCode,response.developerMessage); var resultSet = {rawDataJson : ""} } -- libgit2 0.21.2