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.

Feature Request: Pass Response to `Retry.is_retry()`

See original GitHub issue

I’m working on some tools for using the Internet Archive’s Wayback Machine APIs and it’d be really helpful if I could write a custom Retry class that can look at the the response headers to determine whether a retry is warranted. In particular, when requesting the snapshot of a URL, it’s possible to get an error code that might be coming from the wayback machine or might be coming from the snapshot itself (i.e. the original URL returned the error code when it was scraped). You can determine which of these situations you’re dealing with by looking for the Memento-Datetime header, but Retry.is_retry(), which seems like the right place to do this, doesn’t have access to that info.

It feels like there ought to be plenty of other odd cases where more info about the response would be helpful, so I’m wondering if passing it directly to Retry.is_retry() would be a good idea. Since this gets called before Retry.increment() adds request info to the history, passing the URL might be nice, too.

I’d love to change this signature:

def is_retry(self, method, status_code, has_retry_after=False):

to:

def is_retry(self, method, url, response):

(status_code and has_retry_after can both be obtained from the response object, and can even be handled slightly more efficiently by not asking for them before they’re needed, since is_retry() returns early in some cases.)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sethmlarsoncommented, Sep 20, 2018

At a minimum I’ll mark this as something for 2.0.0 because I agree that we should be passing the whole response into the Retry object to allow for better subclassing potential.

0reactions
Mr0grogcommented, Dec 11, 2021

Yep, the approach in #2500 would certainly work for my case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

There is no way to assign new ReadStream to a body on ...
I'm trying to configure Got to retry on my POST requests. I pass Node's ReadStream created by fs.createReadStream() to the body option.
Read more >
Add Retries to HTTP requests
First, we add our new configuration argument (1). Then, set up the setTimeout and use the backoff value as the delay. Finally, when...
Read more >
Retry-After - HTTP - MDN Web Docs
The Retry-After response HTTP header indicates how long the user agent should wait before making a follow-up request.
Read more >
c# - Cleanest way to write retry logic?
I would like to rewrite this in a general retry function like: TryThreeTimes(DoSomething);. Is it possible in C#? What would be the code...
Read more >
Transient fault handling
You should only retry operations where the faults are transient ... the application can resume normal operations and pass requests to the ...
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