I know that axios interceptors can handle bot ok and ko
axios.interceptors.response.use(
// onFullfilled
function(axios_response) {
return axios_response;
},
// onRejected
function(axios_error) {
console.log(axios_error);
return Promise.reject(axios_error);
}
)
My exact question is: how can I throw an error inside onRejected in a way to be able to handle then in the sibling onRejected?
I tried this
// onFullfilled
function(axios_response) {
if (!axios_response.data) return axios_response;
const { data } = axios_response;
if (!data.status || !data.message) return axios_response;
const { status, message } = data;
console.log("status", status);
console.log("message", message);
if (status === "error") {
return Promise.reject(axios_response);
}
return axios_response;
},
But it's the wrong way, I think, because my rejection is not caught by the interceptor's onRejected handler.