MCPcopy
hub / github.com/pallets/flask / handle_user_exception

Method handle_user_exception

src/flask/app.py:779–809  ·  view source on GitHub ↗

This method is called whenever an exception occurs that should be handled. A special case is :class:`~werkzeug .exceptions.HTTPException` which is forwarded to the :meth:`handle_http_exception` method. This function will either return a response value or reraise the e

(
        self, e: Exception
    )

Source from the content-addressed store, hash-verified

777 return self.ensure_sync(handler)(e) # type: ignore[no-any-return]
778
779 def handle_user_exception(
780 self, e: Exception
781 ) -> HTTPException | ft.ResponseReturnValue:
782 """This method is called whenever an exception occurs that
783 should be handled. A special case is :class:`~werkzeug
784 .exceptions.HTTPException` which is forwarded to the
785 :meth:`handle_http_exception` method. This function will either
786 return a response value or reraise the exception with the same
787 traceback.
788
789 .. versionchanged:: 1.0
790 Key errors raised from request data like ``form`` show the
791 bad key in debug mode rather than a generic bad request
792 message.
793
794 .. versionadded:: 0.7
795 """
796 if isinstance(e, BadRequestKeyError) and (
797 self.debug or self.config["TRAP_BAD_REQUEST_ERRORS"]
798 ):
799 e.show_exception = True
800
801 if isinstance(e, HTTPException) and not self.trap_http_exception(e):
802 return self.handle_http_exception(e)
803
804 handler = self._find_error_handler(e, request.blueprints)
805
806 if handler is None:
807 raise
808
809 return self.ensure_sync(handler)(e) # type: ignore[no-any-return]
810
811 def handle_exception(self, e: Exception) -> Response:
812 """Handle an exception that did not have an error handler

Callers 1

full_dispatch_requestMethod · 0.95

Calls 4

handle_http_exceptionMethod · 0.95
ensure_syncMethod · 0.95
trap_http_exceptionMethod · 0.80
_find_error_handlerMethod · 0.80

Tested by

no test coverage detected