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

Base httpexception classes and exception_response function #1832

Closed
evkar opened this issue Jun 9, 2015 · 4 comments
Closed

Base httpexception classes and exception_response function #1832

evkar opened this issue Jun 9, 2015 · 4 comments

Comments

@evkar
Copy link

evkar commented Jun 9, 2015

I cannot catch HTTPBadRequest exception in case:

try:
    # some code
    raise exception_response(400)
except HTTPBadRequest as e:
    # this code will not be invoked because 
    # exception_response function throws HTTPClientError for 400-status

Of cource, i could replace code with:

try:
    # some code
    raise HTTPBadRequest()
except HTTPBadRequest as e:
    # catch exception

But exception_response function is used by third party code, and i cannot change it.
Also this bug applies for 500-status errors

@tseaver
Copy link
Member

tseaver commented Jun 9, 2015

Thanks for the report!

HTTPClientError is an "abstract base" for all the 4xx-level errors. Similarly, HTTPServerError is a base for all the 5xx errors. Neither should have a code, and therefore should not be raised when looking up a code in the status_map.

@evkar
Copy link
Author

evkar commented Jun 9, 2015

Thanks for the reply

httpexceptions.py contains next lines (pyramid 1.5.6):

class HTTPClientError(HTTPError):
    """
    base class for the 400s, where the client is in error

    This is an error condition in which the client is presumed to be
    in-error.  This is an expected problem, and thus is not considered
    a bug.  A server-side traceback is not warranted.  Unless specialized,
    this is a '400 Bad Request'
    """
    code = 400
    title = 'Bad Request'
    explanation = ('The server could not comply with the request since '
                   'it is either malformed or otherwise incorrect.')

class HTTPBadRequest(HTTPClientError):
    """
    subclass of :class:`~HTTPClientError`

    This indicates that the body or headers failed validity checks,
    preventing the server from being able to continue processing.

    code: 400, title: Bad Request
    """
    pass

Base class has a code equals 400. Unfortunately HTTPClientError is raised instead of HTTPBadRequest when we are looking up a code in the status_map

tseaver added a commit that referenced this issue Jun 9, 2015
…se'.

The base classes are not appropriate for ``400`` and ``500`` status codes.

See:  #1832
tseaver added a commit that referenced this issue Jun 9, 2015
…se'.

The base classes are not appropriate for 400 and 500 status codes.

See: #1832
tseaver added a commit that referenced this issue Jun 9, 2015
The base classes are not appropriate for ``400`` and ``500`` status
codes.

See:  #1832
tseaver added a commit that referenced this issue Jun 9, 2015
…se'.

The base classes are not appropriate for 400 and 500 status codes.

See: #1832
@tseaver
Copy link
Member

tseaver commented Jun 9, 2015

Fixed via: #1833, #1834, #1835, #1836

@tseaver tseaver closed this as completed Jun 9, 2015
@evkar
Copy link
Author

evkar commented Jun 13, 2015

Thanks!

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

No branches or pull requests

2 participants