Skip to content

Reduce overhead of Response.ok #6989

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Reduce overhead of Response.ok #6989

wants to merge 1 commit into from

Conversation

xmo-odoo
Copy link

Every time ok is used it feels like it should be essentially free, but it's not as it goes through raise_for_status which does a bunch of preparatory work to manage the reason and check for the two main error categories separately.

Reduce ok to just check for what it says it does in the first line.

Also makes the behaviour consistent with the docstring: before this change ok would return True if the status code is 600 or above (which some API providers are known to do e.g. Shopify can return 7831, LinkedIn has been known to return 9992. However for that reason it is, technically, a breaking change.

Footnotes

  1. https://shopify.dev/docs/api/usage/response-codes

  2. https://stackoverflow.com/questions/27231113/999-error-code-on-head-request-to-linkedin

Every time `ok` is used it feels like it should be essentially free, but it's not as it goes through `raise_for_status` which does a bunch of preparatory work to manage the reason and check for the two main error categories separately.

Reduce `ok` to just check for what it says it does in the first line.

Also makes the behaviour consistent with the docstring: before this change `ok` would return `True` if the status code is 600 or above (which some API providers are known to do e.g. Shopify can return 783[^1], LinkedIn has been known to return 999[^2]. However for that reason it is, technically, a breaking change.

[^1]: https://shopify.dev/docs/api/usage/response-codes
[^2]: https://stackoverflow.com/questions/27231113/999-error-code-on-head-request-to-linkedin
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.

1 participant