Expose retry metadata on WebPushException - #212
Conversation
jrconlin
left a comment
There was a problem hiding this comment.
Thanks! This is a really nice add.
I have a couple of minor nits, if you want to address them, or talk about them. I don't like to push out versions on Fridays, so I'll wait 'til next week to make any new releases.
| @@ -1,5 +1,10 @@ | |||
| # I am terrible at keeping this up-to-date. | |||
|
|
|||
| ## Unreleased | |||
There was a problem hiding this comment.
Might as well pre-emptively bump the version since this is going to be a new release.
There was a problem hiding this comment.
Addressed in e7b59ff: bumped the package and changelog version to 2.5.0.
| """Return the provider's Retry-After header, when present.""" | ||
| if self.response is None: | ||
| return None | ||
| headers = getattr(self.response, "headers", None) |
There was a problem hiding this comment.
You could collapse this to:
return getattr(self.response, "headers", {}).get("Retry-After", None)
There was a problem hiding this comment.
Addressed in e7b59ff: simplified retry_after using the suggested getattr(...).get(...) form.
|
|
||
| @property | ||
| def retry_after(self) -> str | None: | ||
| """Return the provider's Retry-After header, when present.""" |
There was a problem hiding this comment.
I always hate how "foot-gun" the Retry-After header is. While it's not our role to educate, we should probably include a link to https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Retry-After with a caution about the fact that the value returned can be either number of seconds to wait, or the date stamp of the time to retry.
There was a problem hiding this comment.
Addressed in e7b59ff: documented that Retry-After may be delay seconds or an HTTP date and linked the MDN reference in both the property docstring and usage example.
|
Thanks for the review. I addressed all three suggestions in e7b59ff. Locally, 42 tests pass and Black, isort, and Bandit checks are clean. The updated GitHub Actions run is currently awaiting maintainer approval. |
|
Thanks again. In the future, can you make sure you sign all your commits? It just makes sure that the commits come from you directly, and really helps with auditing. |
Summary
Motivation
Synchronous responses use status_code while asynchronous aiohttp responses use status. Consumers implementing reliable retry behavior currently need transport-specific branching. These additive properties provide one interface for both paths without changing existing exception behavior.
Validation