question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How do I use this with existing error interceptors?

See original GitHub issue

This 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:open
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
DaveSteincommented, Jun 2, 2020

@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 of onError (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?

1reaction
DaveSteincommented, Mar 2, 2020

@JustinBeckwith any suggestion here? 🙏

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found