Call to the Adapter Libraries
- 05 Dec 2022
-
DarkLight
-
PDF
Call to the Adapter Libraries
- Updated on 05 Dec 2022
-
DarkLight
-
PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
Call to Adapter Libraries
The last part of the API methods includes the call to the adapter libraries.
-
The entity must match the name of the entity directory.
-
The action must match the name of the action in the action.json file.
-
The returnDataFlag tells the adapter libraries whether to send back data or return a success/fail flag.
-
You can customize what happens when errors occur as well as alter the data that is returned from the adapter.
-
Remember: Translation is less work if you define the schema and allow the adapter libraries to handle it. There may be cases, however, where you need to modify the data being returned.
Example: Call to Adapter Library in adapter.js
// 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
return callback(irReturnData, null);
});
Was this article helpful?