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

Method _find_error_handler

src/flask/sansio/app.py:823–846  ·  view source on GitHub ↗

Return a registered error handler for an exception in this order: blueprint handler for a specific code, app handler for a specific code, blueprint handler for an exception class, app handler for an exception class, or ``None`` if a suitable handler is not found.

(
        self, e: Exception, blueprints: list[str]
    )

Source from the content-addressed store, hash-verified

821 return f
822
823 def _find_error_handler(
824 self, e: Exception, blueprints: list[str]
825 ) -> ft.ErrorHandlerCallable | None:
826 """Return a registered error handler for an exception in this order:
827 blueprint handler for a specific code, app handler for a specific code,
828 blueprint handler for an exception class, app handler for an exception
829 class, or ``None`` if a suitable handler is not found.
830 """
831 exc_class, code = self._get_exc_class_and_code(type(e))
832 names = (*blueprints, None)
833
834 for c in (code, None) if code is not None else (None,):
835 for name in names:
836 handler_map = self.error_handler_spec[name][c]
837
838 if not handler_map:
839 continue
840
841 for cls in exc_class.__mro__:
842 handler = handler_map.get(cls)
843
844 if handler is not None:
845 return handler
846 return None
847
848 def trap_http_exception(self, e: Exception) -> bool:
849 """Checks if an HTTP exception should be trapped or not. By default

Callers 3

handle_http_exceptionMethod · 0.80
handle_user_exceptionMethod · 0.80
handle_exceptionMethod · 0.80

Calls 2

getMethod · 0.45

Tested by

no test coverage detected