Axios Response Interceptor

Table of contents

  1. Usage
  2. Future work

Orka provides the ability to intercept responses of applications that use axios, via the usage of axios interceptors. In this manner, it is possible to properly propagate an error thrown by axios using its respective status code, instead of manually catching these errors and explicitly specifying the status code.

Axios is an optional dependency. In order to use the interceptor, install the dependency first:

npm i axios

Usage

const { helpers } = ('@workablehr/orka');
helpers.axiosErrorInterceptor();

Having done that, when the application calls another service and receives an error from axios (e.g., a 404) and left unhandled, the application will finally throw a 404.

Future work

This functionality can be further extended in order to support interceptors for requests too.