diff options
| author | Michael Merickel <michael@merickel.org> | 2018-05-15 21:28:42 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-15 21:28:42 -0500 |
| commit | 07378673d8eb974069cbae2cd111eb03a9853910 (patch) | |
| tree | 833a7b97f050b79d4c10a825df98c42bd576a27a | |
| parent | 0d9792f84c63b7e07b30c083b40082f46e03e29f (diff) | |
| parent | 829cc3d225a7a9f09c77c5184243e4db09179225 (diff) | |
| download | pyramid-07378673d8eb974069cbae2cd111eb03a9853910.tar.gz pyramid-07378673d8eb974069cbae2cd111eb03a9853910.tar.bz2 pyramid-07378673d8eb974069cbae2cd111eb03a9853910.zip | |
Merge pull request #3280 from cewing/issue-3212
Fix inadvertent 520 error codes
| -rw-r--r-- | CHANGES.rst | 5 | ||||
| -rw-r--r-- | pyramid/httpexceptions.py | 19 |
2 files changed, 18 insertions, 6 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 4cb8ba44b..1771026fc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -28,6 +28,11 @@ Features Bug Fixes --------- +- Set appropriate ``code`` and ``title`` attributes on the ``HTTPClientError`` and + ``HTTPServerError`` exception classes. This prevents inadvertently returning a 520 + error code. + See https://github.com/Pylons/pyramid/pull/3280 + Deprecations ------------ diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index 1f3934fdc..734080434 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -606,7 +606,8 @@ class HTTPClientError(HTTPError): a bug. A server-side traceback is not warranted. Unless specialized, this is a '400 Bad Request' """ - pass + code = 400 + title = 'Bad Request' class HTTPBadRequest(HTTPClientError): """ @@ -617,8 +618,6 @@ class HTTPBadRequest(HTTPClientError): code: 400, title: Bad Request """ - code = 400 - title = 'Bad Request' explanation = ('The server could not comply with the request since ' 'it is either malformed or otherwise incorrect.') @@ -1032,11 +1031,18 @@ class HTTPServerError(HTTPError): This is an error condition in which the server is presumed to be in-error. Unless specialized, this is a '500 Internal Server Error'. """ - pass - -class HTTPInternalServerError(HTTPServerError): code = 500 title = 'Internal Server Error' + +class HTTPInternalServerError(HTTPServerError): + """ + subclass of :class:`~HTTPServerError` + + This indicates that the server encountered an unexpected condition + which prevented it from fulfilling the request. + + code: 500, title: Internal Server Error + """ explanation = ( 'The server has either erred or is incapable of performing ' 'the requested operation.') @@ -1150,6 +1156,7 @@ for name, value in list(globals().items()): if ( isinstance(value, class_types) and issubclass(value, HTTPException) and + value not in {HTTPClientError, HTTPServerError} and not name.startswith('_') ): code = getattr(value, 'code', None) |
