simplify InternalServerError.original_exception

This commit is contained in:
David Lord 2021-01-29 11:26:17 -08:00
parent eb42655c46
commit 64206c13c2
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 5 additions and 22 deletions

View file

@ -249,25 +249,11 @@ be passed an instance of ``InternalServerError``, not the original
unhandled error. unhandled error.
The original error is available as ``e.original_exception``. The original error is available as ``e.original_exception``.
Until Werkzeug 1.0.0, this attribute will only exist during unhandled
errors, use ``getattr`` to get access it for compatibility.
.. code-block:: python An error handler for "500 Internal Server Error" will be passed uncaught
exceptions in addition to explicit 500 errors. In debug mode, a handler
@app.errorhandler(InternalServerError) for "500 Internal Server Error" will not be used. Instead, the
def handle_500(e): interactive debugger will be shown.
original = getattr(e, "original_exception", None)
if original is None:
# direct 500 error, such as abort(500)
return render_template("500.html"), 500
# wrapped unhandled error
return render_template("500_unhandled.html", e=original), 500
An error handler for "500 Internal Server Error" will be passed uncaught exceptions in
addition to explicit 500 errors. In debug mode, a handler for "500 Internal Server Error" will not be used.
Instead, the interactive debugger will be shown.
Custom Error Pages Custom Error Pages

View file

@ -1447,10 +1447,7 @@ class Flask(Scaffold):
raise e raise e
self.log_exception(exc_info) self.log_exception(exc_info)
server_error = InternalServerError() server_error = InternalServerError(original_exception=e)
# TODO: pass as param when Werkzeug>=1.0.0 is required
# TODO: also remove note about this from docstring and docs
server_error.original_exception = e
handler = self._find_error_handler(server_error) handler = self._find_error_handler(server_error)
if handler is not None: if handler is not None: