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

edit2: https://stackoverflow.com/a/4168328/216832 assumes that I do not need to worry, because this does not happen when on a real device.


I use Axios in a VueJS hybrid application (Cordova) and call the API.

Axios (correctly) makes a "preflight" request OPTIONSbefore my GET/ requests POST, but if the API returns 503at that moment, my error handling code is not called.

HTTP.post(url, data, {headers: {Authorization: 'Bearer ' + token.getAccessToken()}})
  .then(response => response)
  .catch(error => {
    // Not reached
  });
Run codeHide result

How can I catch this error status?


edit : screenshot from Chrome Dev Tools:

503 on OPTIONS request

+8
source share
2

,

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

,

Network error

+4

Network Error . , - , , , , :

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;
});
0

All Articles