Skip to content
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

Add helper method to raise an exception for error status codes #868

Closed
Kentzo opened this issue May 6, 2016 · 3 comments
Closed

Add helper method to raise an exception for error status codes #868

Kentzo opened this issue May 6, 2016 · 3 comments

Comments

@Kentzo
Copy link

Kentzo commented May 6, 2016

Long story short

aiohttp should provide a helper's method to check for errors in responses. Something like request's raise_for_error.

@Kentzo
Copy link
Author

Kentzo commented May 6, 2016

Something like:

ClientResponse:
    …
    def raise_for_status(self):
         http_error_msg = ''

        if 400 <= self.status< 500:
            http_error_msg = 'Client Error: {}'.format(self.reason)
        elif 500 <= self.status < 600:
            http_error_msg = 'Server Error: {}'.format(self.reason)

        if http_error_msg:
            raise aiohttp.HttpProcessingError(code=self.status, message=http_error_msg)

(borrowed from requests)

@asvetlov
Copy link
Member

asvetlov commented Jun 2, 2016

Good to have.
Not sure about exact exception type though.

@asvetlov asvetlov added the sprint label Jun 2, 2016
djmitche added a commit to djmitche/aiohttp that referenced this issue Jun 3, 2016
This method raises an exception for statuses that represent an error.
Closes aio-libs#868.
@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants