Skip to content
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

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

Open
DaveStein opened this issue Feb 6, 2020 · 7 comments
Open

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

DaveStein opened this issue Feb 6, 2020 · 7 comments
Labels
question Further information is requested

Comments

@DaveStein
Copy link

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.

@DaveStein
Copy link
Author

PS: If it's not clear, the second call to my generic handler does not receive the configuration object for axios so I can't get the details for my logs. The first does. I only want to log the second.

@JustinBeckwith JustinBeckwith added the question Further information is requested label Feb 10, 2020
@DaveStein
Copy link
Author

@JustinBeckwith is this something you can answer or do you think this is more of a Stack Overflow Question? I'm kind of wondering if there's a feature request in here for like "callback for final error" such that you get it after failed number of retries or the failure case for requests that don't get retries.

@DaveStein
Copy link
Author

@JustinBeckwith any suggestion here? 🙏

@JustinBeckwith
Copy link
Owner

Greetings! Not something I've had time to look into, apologies.

@DaveStein
Copy link
Author

@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?

@danthareja
Copy link

@DaveStein - did you ever find a solution for this?

@DaveStein
Copy link
Author

@danthareja we made our own interceptor that would instantiate a new instance of axios and go from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants