Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore interceptors in axios as a parameter?

Tags:

javascript

I have axios interceptors, is it possible to ignore interceptors for one request by invoke the axios method?

something like: axios.post('/path/foo', null, { ignoreInterceptors: true } })

axios.interceptors.response.use(
  (response) => {
    return response;
  },
  (error) => {
    return Promise.reject(error);
  }
);
like image 282
Jon Sud Avatar asked Aug 15 '20 06:08

Jon Sud


People also ask

How do you remove interceptors from Axios?

If you need to remove an interceptor later you can. const myInterceptor = axios. interceptors. request.

How do you pass data in Axios interceptor?

To pass parameter or argument to Axios interceptor with JavaScript, we can add it to the config. params object. We add the myVar property to config. params by spreading its existing properties into a new object and then add myVar after it.

Can we add interceptors to a custom instance of Axios?

The steps to create Axios request & response interceptors are: Create a new Axios instance with a custom config. Create request, response & error handlers. Configure/make use of request & response interceptors from Axios.

How do request interceptors work in Axios?

Axios calls request interceptors before sending the request, so you can use request interceptors to modify the request. Axios calls response interceptors after it sends the request and receives a response.

What are request interceptors and response interceptors?

There are two types of interceptors: request interceptors and response interceptors. The previous example was a request interceptor. Axios calls request interceptors before sending the request, so you can use request interceptors to modify the request. Axios calls response interceptors after it sends the request and receives a response.

How to handle errors in Axios?

To handle errors in Axios you should use axios.interceptors.response.use () function which takes two arguments successHandler and errorHandler, The first one successHandler is called if the request is successful and the errorHandler is called if the request failed.

What is the 2nd parameter to Axios get ()?

The 2nd parameter to axios.get () is the Axios options: Axios will serialize options.params and add it to the query string for you as shown below. You can set options.params to a POJO as shown above, or to an instance of the JavaScript's built-in URLSearchParams class.


1 Answers

Instead of:

axios.post('/path/foo')

you do:

const uninterceptedAxiosInstance = axios.create();
uninterceptedAxiosInstance.post('/path/foo')

and nothing will intercept that request.

like image 91
SudoPlz Avatar answered Oct 07 '22 01:10

SudoPlz