Handle status (e.g. 503) in Axios OPTIONS response Handle status (e.g. 503) in Axios OPTIONS response vue.js vue.js

Handle status (e.g. 503) in Axios OPTIONS response


I was able to reproduce the issue and the simplest fix I could find as below

axios.interceptors.response.use(null, (error) => {    return Promise.reject(error);});

As you can see in my tests I was able to get the error for and response for different scenarios

Network error


Axios' Network Error isn't much descriptive. To rethrow it in a better way, we can do something like this, to at least describe what request got the error, and what happened:

instance.interceptors.response.use(null, error => {  if (error && error.message === 'Network Error') {    throw new Error(`Potential network CORS preflight error at ${error.config.url}`);  }  throw error;});


Who want know what type of http status is response with axios interceptor that is a example

    axios.interceptors.response.use(function (res) {        return res;      },      (err) => {        if(err.response.status == 403 || err.response.status == 503) {            //handle error of type            obj[err.response.status] ? obj[err.response.status]() : obj["default"]();        }        return Promise.reject(err);      });

You can made a map with status callback for diferent behaviours.

const obj = {    503 : () => console.log("Forbidden"),    417 : () => console.log("is a teepot"),    'default': () => console.log("Not handle it")}