From 391275df4eabfb2be0c8cac5de70e3a5fad5acfd Mon Sep 17 00:00:00 2001 From: Cris Ewing Date: Mon, 14 May 2018 17:07:00 -0400 Subject: Move base server and client error codes and titles to the base classes. Add a docstring to the HTTPInternalServerError --- pyramid/httpexceptions.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index 1f3934fdc..4702a6e8e 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.') -- cgit v1.2.3 From 5a99ad864161750bd05ddf1df368701d64c0a396 Mon Sep 17 00:00:00 2001 From: Cris Ewing Date: Mon, 14 May 2018 17:09:10 -0400 Subject: Update the building of status_dict, now that both the base server and client errors and their specific implementations share an error code. Ensures we only get the specific implementations in status_dict --- pyramid/httpexceptions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index 4702a6e8e..ac4f57738 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -1156,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) -- cgit v1.2.3 From 19beeacc7e42d026480e16c69e0332082229f341 Mon Sep 17 00:00:00 2001 From: Cris Ewing Date: Mon, 14 May 2018 17:18:56 -0400 Subject: Sets, when you absolutely, positively want those extra microseconds back --- pyramid/httpexceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index ac4f57738..734080434 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -1156,7 +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 + value not in {HTTPClientError, HTTPServerError} and not name.startswith('_') ): code = getattr(value, 'code', None) -- cgit v1.2.3 From 829cc3d225a7a9f09c77c5184243e4db09179225 Mon Sep 17 00:00:00 2001 From: Cris Ewing Date: Tue, 15 May 2018 10:41:10 -0400 Subject: Add changelog entry for this bugfix --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) 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 ------------ -- cgit v1.2.3