Customizing the Response
- 05 Dec 2022
-
DarkLight
-
PDF
Customizing the Response
- Updated on 05 Dec 2022
-
DarkLight
-
PDF
Article Summary
Share feedback
Thanks for sharing your feedback!
You can change any information in the response within adapter.js prior to sending it back to IAP. This includes:
- Handling embedded errors that may not be detected by the generic adapter libraries.
- Performing calculations on the data that is returned and adding the results into the response.
- There is no need to do translations here if schemas are set up properly, but you can if it is desired.
Example: Customizing the response.
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest(‘entity’, ‘action', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or there is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response’, [‘action’], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
const newObj = {
number: irReturnData.response.length,
data: irReturnData.response
}
return callback(newObj, null);
});
Was this article helpful?