Skip to content

Expose retry metadata on WebPushException - #212

Merged
jrconlin merged 2 commits into
web-push-libs:mainfrom
Ays-Net:feat/webpush-exception-metadata
Aug 29, 2026
Merged

Expose retry metadata on WebPushException#212
jrconlin merged 2 commits into
web-push-libs:mainfrom
Ays-Net:feat/webpush-exception-metadata

Conversation

@Alibehram11

Copy link
Copy Markdown
Contributor

Summary

  • expose a common WebPushException.status_code property for requests and aiohttp responses
  • expose the provider Retry-After header through WebPushException.retry_after
  • document retry handling and retain the original response object unchanged

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

  • 42 upstream tests passed
  • Black check passed
  • isort check passed
  • Bandit check passed
  • git diff --check passed

@jrconlin jrconlin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread CHANGELOG.md Outdated
@@ -1,5 +1,10 @@
# I am terrible at keeping this up-to-date.

## Unreleased

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well pre-emptively bump the version since this is going to be a new release.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e7b59ff: bumped the package and changelog version to 2.5.0.

Comment thread pywebpush/__init__.py Outdated
"""Return the provider's Retry-After header, when present."""
if self.response is None:
return None
headers = getattr(self.response, "headers", None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could collapse this to:

return getattr(self.response, "headers", {}).get("Retry-After", None)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e7b59ff: simplified retry_after using the suggested getattr(...).get(...) form.

Comment thread pywebpush/__init__.py Outdated

@property
def retry_after(self) -> str | None:
"""Return the provider's Retry-After header, when present."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Alibehram11

Copy link
Copy Markdown
Contributor Author

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.

@jrconlin

Copy link
Copy Markdown
Member

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.

@jrconlin
jrconlin merged commit 7c2e75f into web-push-libs:main Aug 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants