-
-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Closed
Copy link
Description
Describe the issue
As the usage in README.md, a request interceptors will be like:
axios.interceptors.request.use(function onFulfilled(config) {
// Do something before request is sent
return config;
}, function onRejected(error) {
// Do something with request error
return Promise.reject(error);
});However, the onRejected function will handle the error in the next request intercetor onFulfilled.
Example Code
instance.interceptors.request.use((config) => {
throw new Error("Error in req1");
return config;
}, (error) => {
console.log("req1 handle the error", error);
return Promise.reject(error);
})
instance.interceptors.request.use((config) => {
throw new Error("Error in req2");
return config;
}, (error) => {
console.log("req2 handle the error", error);
return Promise.reject(error);
})
instance.get("some site").then((res) => {
console.log("get res")
}, (err) => {
console.log("get err", err);
})The output in console will be:
req1 handle error Error: Error in req2
get err Error: Error in req2
Expected behavior, if applicable
The better behavior may be that the error will be handled by function in the same request interceptor, I think.
Environment
- Axios Version: 0.26.1
- Adapter: HTTP
- Node.js Version :16.14.0
- OS: Windows 10
Additional context/Screenshots
The following graph was drawn according to the source code. It may be helpful.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
