Hi Team...
Please suggest best practises for handling error / exceptions inside the Gateway script code and stop processing the assembly. We have tried session.reject and it is returning 500 Internal server error with default JSON as below. But in such cases, we wanted to form a generic JSON response and return it back to the consumer. Please advise how this can be achieved. Thanks
Code during user exception in Gateway script
if(apicTimestamp > consentExpiry){
console.error('Consent Expired' );
var respRoot = 'GetAccountListRes';
var resp={};
resp[respRoot] = {};
resp[respRoot].ResponseHeader = {};
resp[respRoot].ResponseHeader.ErrorDetails = {};
resp[respRoot].ResponseHeader.ErrorDetails.ErrorInfo = {};
resp[respRoot].ResponseHeader.ErrorDetails.ErrorInfo.ErrorCode = 'SYS_ERR';
resp[respRoot].ResponseHeader.ErrorDetails.ErrorInfo.ErrorShortDesc = 'Consent Expired.';
session.reject("Consent Expired");
context.message.body.write(resp);
context.message.header.set('Content-Type', "text/JSON");
return;
}
else{
console.error('Consent Valid' );
}
Response received during session.reject is below by default, but please advise how can we return entire Response object and stop further processing.
{
"httpCode": "500",
"httpMessage": "Internal Server Error",
"moreInformation": "Consent Expired"
}
------------------------------
Ashok Beshra
------------------------------