Method: flask.app.Flask.trap_http_exception
Calls: 74, Exceptions: 0, Paths: 6Back
Path 1: 65 calls (0.88)
NotFound (16) Forbidden (16) MethodNotAllowed (14) InternalServerError (9) BadRequest (2) test_http_error_subclass_handling.
False (65)
1def trap_http_exception(self, e: Exception) -> bool:
2 """Checks if an HTTP exception should be trapped or not. By default
3 this will return ``False`` for all exceptions except for a bad request
4 key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It
5 also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.
6
7 This is called for all HTTP exceptions raised by a view function.
8 If it returns ``True`` for any exception the error handler for this
9 exception is not called and it shows up as regular exception in the
10 traceback. This is helpful for debugging implicitly raised HTTP
11 exceptions.
12
13 .. versionchanged:: 1.0
14 Bad request errors are not trapped by default in debug mode.
15
16 .. versionadded:: 0.8
17 """
18 if self.config["TRAP_HTTP_EXCEPTIONS"]:
19 return True
20
21 trap_bad_request = self.config["TRAP_BAD_REQUEST_ERRORS"]
22
23 # if unset, trap key errors in debug mode
24 if (
25 trap_bad_request is None
26 and self.debug
27 and isinstance(e, BadRequestKeyError)
28 ):
29 return True
30
31 if trap_bad_request:
32 return isinstance(e, BadRequest)
33
34 return False
Path 2: 3 calls (0.04)
BadRequest (1) RequestRedirect (1) MethodNotAllowed (1)
False (3)
1def trap_http_exception(self, e: Exception) -> bool:
2 """Checks if an HTTP exception should be trapped or not. By default
3 this will return ``False`` for all exceptions except for a bad request
4 key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It
5 also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.
6
7 This is called for all HTTP exceptions raised by a view function.
8 If it returns ``True`` for any exception the error handler for this
9 exception is not called and it shows up as regular exception in the
10 traceback. This is helpful for debugging implicitly raised HTTP
11 exceptions.
12
13 .. versionchanged:: 1.0
14 Bad request errors are not trapped by default in debug mode.
15
16 .. versionadded:: 0.8
17 """
18 if self.config["TRAP_HTTP_EXCEPTIONS"]:
19 return True
20
21 trap_bad_request = self.config["TRAP_BAD_REQUEST_ERRORS"]
22
23 # if unset, trap key errors in debug mode
24 if (
25 trap_bad_request is None
26 and self.debug
27 and isinstance(e, BadRequestKeyError)
28 ):
29 return True
30
31 if trap_bad_request:
32 return isinstance(e, BadRequest)
33
34 return False
Path 3: 2 calls (0.03)
BadRequestKeyError (1) BadRequest (1)
True (2)
1def trap_http_exception(self, e: Exception) -> bool:
2 """Checks if an HTTP exception should be trapped or not. By default
3 this will return ``False`` for all exceptions except for a bad request
4 key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It
5 also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.
6
7 This is called for all HTTP exceptions raised by a view function.
8 If it returns ``True`` for any exception the error handler for this
9 exception is not called and it shows up as regular exception in the
10 traceback. This is helpful for debugging implicitly raised HTTP
11 exceptions.
12
13 .. versionchanged:: 1.0
14 Bad request errors are not trapped by default in debug mode.
15
16 .. versionadded:: 0.8
17 """
18 if self.config["TRAP_HTTP_EXCEPTIONS"]:
19 return True
20
21 trap_bad_request = self.config["TRAP_BAD_REQUEST_ERRORS"]
22
23 # if unset, trap key errors in debug mode
24 if (
25 trap_bad_request is None
26 and self.debug
27 and isinstance(e, BadRequestKeyError)
28 ):
29 return True
30
31 if trap_bad_request:
32 return isinstance(e, BadRequest)
33
34 return False
Path 4: 2 calls (0.03)
BadRequest (2)
False (2)
1def trap_http_exception(self, e: Exception) -> bool:
2 """Checks if an HTTP exception should be trapped or not. By default
3 this will return ``False`` for all exceptions except for a bad request
4 key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It
5 also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.
6
7 This is called for all HTTP exceptions raised by a view function.
8 If it returns ``True`` for any exception the error handler for this
9 exception is not called and it shows up as regular exception in the
10 traceback. This is helpful for debugging implicitly raised HTTP
11 exceptions.
12
13 .. versionchanged:: 1.0
14 Bad request errors are not trapped by default in debug mode.
15
16 .. versionadded:: 0.8
17 """
18 if self.config["TRAP_HTTP_EXCEPTIONS"]:
19 return True
20
21 trap_bad_request = self.config["TRAP_BAD_REQUEST_ERRORS"]
22
23 # if unset, trap key errors in debug mode
24 if (
25 trap_bad_request is None
26 and self.debug
27 and isinstance(e, BadRequestKeyError)
28 ):
29 return True
30
31 if trap_bad_request:
32 return isinstance(e, BadRequest)
33
34 return False
Path 5: 1 calls (0.01)
BadRequestKeyError (1)
True (1)
1def trap_http_exception(self, e: Exception) -> bool:
2 """Checks if an HTTP exception should be trapped or not. By default
3 this will return ``False`` for all exceptions except for a bad request
4 key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It
5 also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.
6
7 This is called for all HTTP exceptions raised by a view function.
8 If it returns ``True`` for any exception the error handler for this
9 exception is not called and it shows up as regular exception in the
10 traceback. This is helpful for debugging implicitly raised HTTP
11 exceptions.
12
13 .. versionchanged:: 1.0
14 Bad request errors are not trapped by default in debug mode.
15
16 .. versionadded:: 0.8
17 """
18 if self.config["TRAP_HTTP_EXCEPTIONS"]:
19 return True
20
21 trap_bad_request = self.config["TRAP_BAD_REQUEST_ERRORS"]
22
23 # if unset, trap key errors in debug mode
24 if (
25 trap_bad_request is None
26 and self.debug
27 and isinstance(e, BadRequestKeyError)
28 ):
29 return True
30
31 if trap_bad_request:
32 return isinstance(e, BadRequest)
33
34 return False
Path 6: 1 calls (0.01)
NotFound (1)
True (1)
1def trap_http_exception(self, e: Exception) -> bool:
2 """Checks if an HTTP exception should be trapped or not. By default
3 this will return ``False`` for all exceptions except for a bad request
4 key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It
5 also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.
6
7 This is called for all HTTP exceptions raised by a view function.
8 If it returns ``True`` for any exception the error handler for this
9 exception is not called and it shows up as regular exception in the
10 traceback. This is helpful for debugging implicitly raised HTTP
11 exceptions.
12
13 .. versionchanged:: 1.0
14 Bad request errors are not trapped by default in debug mode.
15
16 .. versionadded:: 0.8
17 """
18 if self.config["TRAP_HTTP_EXCEPTIONS"]:
19 return True
20
21 trap_bad_request = self.config["TRAP_BAD_REQUEST_ERRORS"]
22
23 # if unset, trap key errors in debug mode
24 if (
25 trap_bad_request is None
26 and self.debug
27 and isinstance(e, BadRequestKeyError)
28 ):
29 return True
30
31 if trap_bad_request:
32 return isinstance(e, BadRequest)
33
34 return False