Customizing the Response
  • 05 Dec 2022
  • Dark
    Light
  • PDF

Customizing the Response

  • Dark
    Light
  • PDF

Article Summary

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?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.