Home / Function/ trap_http_exception() — flask Function Reference

trap_http_exception() — flask Function Reference

Architecture documentation for the trap_http_exception() function in app.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  a3330f8f_4c76_7508_57f5_3f9e325c833a["trap_http_exception()"]
  38f6d4a2_834e_2acd_e1b6_f45c58079ccd["App"]
  a3330f8f_4c76_7508_57f5_3f9e325c833a -->|defined in| 38f6d4a2_834e_2acd_e1b6_f45c58079ccd
  style a3330f8f_4c76_7508_57f5_3f9e325c833a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/sansio/app.py lines 890–923

    def trap_http_exception(self, e: Exception) -> bool:
        """Checks if an HTTP exception should be trapped or not.  By default
        this will return ``False`` for all exceptions except for a bad request
        key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``.  It
        also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.

        This is called for all HTTP exceptions raised by a view function.
        If it returns ``True`` for any exception the error handler for this
        exception is not called and it shows up as regular exception in the
        traceback.  This is helpful for debugging implicitly raised HTTP
        exceptions.

        .. versionchanged:: 1.0
            Bad request errors are not trapped by default in debug mode.

        .. versionadded:: 0.8
        """
        if self.config["TRAP_HTTP_EXCEPTIONS"]:
            return True

        trap_bad_request = self.config["TRAP_BAD_REQUEST_ERRORS"]

        # if unset, trap key errors in debug mode
        if (
            trap_bad_request is None
            and self.debug
            and isinstance(e, BadRequestKeyError)
        ):
            return True

        if trap_bad_request:
            return isinstance(e, BadRequest)

        return False

Subdomains

Frequently Asked Questions

What does trap_http_exception() do?
trap_http_exception() is a function in the flask codebase, defined in src/flask/sansio/app.py.
Where is trap_http_exception() defined?
trap_http_exception() is defined in src/flask/sansio/app.py at line 890.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free