Question: How do I use this with existing error interceptors?
See original GitHub issueThis library looks like exactly what I need. I am trying it out with code like this:
rax.attach();
axios.defaults.raxConfig = {
onRetryAttempt: err => {
const cfg = rax.getConfig(err);
console.log(`Retry attempt #${cfg.currentRetryAttempt}`);
}
};
axios.interceptors.response.use(interceptors.response.success, interceptors.response.error);`
interceptors.response.error
is where I build up custom error for logging, which includes the request & response details. At the top I threw this in:
console.log(e.message);
console.log(typeof e.config);
When I purposefully error via gibberish URL the console.logs output this:
Retry attempt #1
Retry attempt #2
getaddrinfo ENOTFOUND www.asdlkfjaslfkjadflkjfadslfjnafdslkfasd.com www.asdlkfjaslfkjadflkjfadslfjnafdslkfasd.com:80
object
getaddrinfo ENOTFOUND www.asdlkfjaslfkjadflkjfadslfjnafdslkfasd.com www.asdlkfjaslfkjadflkjfadslfjnafdslkfasd.com:80
undefined
How should I ensure that my logic only runs after final attempt AND for any error that has no retries? ie an error with POST, which would never really run onRetryAttempt
Right now it looks to fire your plugin twice followed by my generic handler twice.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How can you use axios interceptors? - Stack Overflow
Assume you have requested some API with valid API credentials, but you do not have the valid role to access the data. So,...
Read more >How to use Axios interceptors to handle API error responses
With interceptors you can hook to a specific lifecycle of the API call, the request and response , and maybe modify the behaviours...
Read more >HTTP Requests and Error Handling with Angular Interceptors
In this cloud tutorial, we will be using interceptors in Angular to handle HTTP requests and responses, and process errors. If you have...
Read more >Top 10 ways to use Interceptors in Angular - Medium
My ten favorite ways to use the interceptor in Angular. With examples of error handling, profiling, caching and more this list will inspire...
Read more >Setting up Axios Interceptors for all HTTP calls in an application
And if the request is somehow malformed, the second function, the error() function will kick in and throw an error rejecting the request...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@JustinBeckwith I realize attach is just doing
return instance.interceptors.response.use(onFulfilled, onError);
If you exported
onError
, that would imply I can just use your same logic in my existing interceptor, and on rejection ofonError
(which I believe happens when the last retry fails), I can grab the error and do what I would usually do.What do you think of that strategy?
@JustinBeckwith any suggestion here? 🙏