I use axios interceptors to get the error. in some cases that I have error I do not want to return to the catch or then callback.
How I do it in axios? because if I dont return value it go to the next
, but if I return Promise.reject
it go to the catch
.
I want when I have error in interceptors, not continue forward to the callback.
import axios from "axios";
axios.interceptors.response.use(
(response) => response,
(error) => {
console.log({ error });
// do not return to the catch/then in foo please! <-- HOW?
return Promise.reject(error);
}
);
const foo = () => {
axios
.post("https://httpstat.us/500")
.then((r) => {
console.log({ r });
})
.catch((err) => {
console.log({ err });
});
};
foo();
you can return a resolve promises in the error function
axios.interceptors.response.use(
(response) => response,
(error) => {
console.log({ error });
return Promise.resolve();
}
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.