edgi-govdata-archiving / wayback

A Python API to the Internet Archive Wayback Machine
https://wayback.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
61 stars 12 forks source link

Don't raise on *archived* rate limit errors #159

Closed Mr0grog closed 7 months ago

Mr0grog commented 7 months ago

A memento can be a archive of an old rate limit error (status code 429) and in our feverish run to handle rate limit errors better at the end of 2023, we caused WaybackSession.send() to raise exceptions for both real rate limits and archived ones. However, the archived ones might be an actual memento that you were looking for, and should have been exempted from raising.

This solves the issue by simply checking whether a response is a memento and returning it immediately without doing any other checks, since the effective status code for a memento is always 200. (Checking various attributes of a memento is complicated, so it’s better to just return them right away rather than remembering to make complex exceptions in all the places where various response attributes have to be treated differently for mementos.)

Fixes #158.

After this lands, I’ll cherry-pick it onto a separate v0.4.x branch so I can cut a v0.4.5 release with the fix, since main is already full of breaking changes scheduled for v0.5.0.