-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to trigger interceptors request error ? #2509
Comments
That request interceptor error will be triggered when there's an error with the interceptor, you can test this by doing: axios.interceptors.request.use(
() => {
throw new Error("My error");
},
() => {
debugger;
}
);
axios
.get("https://jsonplaceholder.typicode.com/users")
.then(res => {
const persons = res.data;
this.setState({ persons });
}); You get to the debugger because there's an error triggered in the interceptor |
The error is not catched and not run debugger... But when register debugger interceptor.request first, and then register other interceptor.request to throw new Error, the debugger is triggered. Can you tell me why? what wrong things with i trying? axios.interceptors.request.use(
() => {
// throw new Error('My error')
},
() => {
debugger
}
)
axios.interceptors.request.use(function (config) {
// Do something before request is sent
throw new Error('My error')
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
}); thanks for your answer! |
@ch-zgh-1993 What you need is some practices about promises. Good luck!
If you are familiar with Promises, you will know that |
I know this. but its right design about catch request.use error? if only one reques.use, what effect about debugger ? // Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
debugger
// Do something with request error
return Promise.reject(error);
}); |
See #1556. Someone has the same curiosity with you. |
which config for request, can tirgger interceptors request error ?
thanks for your answer!
The text was updated successfully, but these errors were encountered: