Apr 16

How to Intercept Request and Response of all API Calls in One Place

In this article, you will learn how to intercept request and responses of all the API calls of the app at once place. The following three functions explain the application service and usage examples.

onBeforeServiceCall

  • onBeforeServiceCall is a function which is called before any service call is sent from the application. This function is useful when the user wants to add a particular header to many calls or to append something to the URL of all service calls in the project. It is present in the app.js file of the project.
  • It accepts a parameter(requestParams) of type wm HttpRequest and should also return a wm HttpRequest. Below are a few ways to manipulate the requestParams parameter:

onServiceSuccess

  • onServiceSuccess is a function which is called after the success of any service call in the application. This is useful when the user wants to manipulate the data received from service calls success in the project. It is present in the app.js file of the project.
  • It accepts two parameters namely data and xhrObj:
    • data contains the success data returned by the call.
    • xhrObj is the complete response received from the network call execution.

onServiceError

  • onServiceError is a function which is called after the failure of any service call in the application. This is useful when the user wants to manipulate the error received from service calls failure in the project. It is present in the app.js file of the project.
  • It accepts two parameters namely errorMsg and xhrObj:
    • errorMsg contains the error message received in the failed call.
    • xhrObj is the complete response received from the network call failure.
 
We use cookies to provide you with a better experience. By using our website you agree to the use of cookies as described in our Privacy Policy.