|
|
@ -1090,14 +1090,14 @@ class Flask(_PackageBoundObject): |
|
|
|
exc_class = default_exceptions[exc_class_or_code] |
|
|
|
exc_class = default_exceptions[exc_class_or_code] |
|
|
|
else: |
|
|
|
else: |
|
|
|
exc_class = exc_class_or_code |
|
|
|
exc_class = exc_class_or_code |
|
|
|
|
|
|
|
|
|
|
|
assert issubclass(exc_class, Exception) |
|
|
|
assert issubclass(exc_class, Exception) |
|
|
|
|
|
|
|
|
|
|
|
if issubclass(exc_class, HTTPException): |
|
|
|
if issubclass(exc_class, HTTPException): |
|
|
|
return exc_class, exc_class.code |
|
|
|
return exc_class, exc_class.code |
|
|
|
else: |
|
|
|
else: |
|
|
|
return exc_class, None |
|
|
|
return exc_class, None |
|
|
|
|
|
|
|
|
|
|
|
@setupmethod |
|
|
|
@setupmethod |
|
|
|
def errorhandler(self, code_or_exception): |
|
|
|
def errorhandler(self, code_or_exception): |
|
|
|
"""A decorator that is used to register a function give a given |
|
|
|
"""A decorator that is used to register a function give a given |
|
|
@ -1166,9 +1166,9 @@ class Flask(_PackageBoundObject): |
|
|
|
'Tried to register a handler for an exception instance {0!r}. ' |
|
|
|
'Tried to register a handler for an exception instance {0!r}. ' |
|
|
|
'Handlers can only be registered for exception classes or HTTP error codes.' |
|
|
|
'Handlers can only be registered for exception classes or HTTP error codes.' |
|
|
|
.format(code_or_exception)) |
|
|
|
.format(code_or_exception)) |
|
|
|
|
|
|
|
|
|
|
|
exc_class, code = self._get_exc_class_and_code(code_or_exception) |
|
|
|
exc_class, code = self._get_exc_class_and_code(code_or_exception) |
|
|
|
|
|
|
|
|
|
|
|
handlers = self.error_handler_spec.setdefault(key, {}).setdefault(code, {}) |
|
|
|
handlers = self.error_handler_spec.setdefault(key, {}).setdefault(code, {}) |
|
|
|
handlers[exc_class] = f |
|
|
|
handlers[exc_class] = f |
|
|
|
|
|
|
|
|
|
|
@ -1460,7 +1460,7 @@ class Flask(_PackageBoundObject): |
|
|
|
# those unchanged as errors |
|
|
|
# those unchanged as errors |
|
|
|
if e.code is None: |
|
|
|
if e.code is None: |
|
|
|
return e |
|
|
|
return e |
|
|
|
|
|
|
|
|
|
|
|
handler = self._find_error_handler(e) |
|
|
|
handler = self._find_error_handler(e) |
|
|
|
if handler is None: |
|
|
|
if handler is None: |
|
|
|
return e |
|
|
|
return e |
|
|
@ -1503,12 +1503,12 @@ class Flask(_PackageBoundObject): |
|
|
|
# wants the traceback preserved in handle_http_exception. Of course |
|
|
|
# wants the traceback preserved in handle_http_exception. Of course |
|
|
|
# we cannot prevent users from trashing it themselves in a custom |
|
|
|
# we cannot prevent users from trashing it themselves in a custom |
|
|
|
# trap_http_exception method so that's their fault then. |
|
|
|
# trap_http_exception method so that's their fault then. |
|
|
|
|
|
|
|
|
|
|
|
if isinstance(e, HTTPException) and not self.trap_http_exception(e): |
|
|
|
if isinstance(e, HTTPException) and not self.trap_http_exception(e): |
|
|
|
return self.handle_http_exception(e) |
|
|
|
return self.handle_http_exception(e) |
|
|
|
|
|
|
|
|
|
|
|
handler = self._find_error_handler(e) |
|
|
|
handler = self._find_error_handler(e) |
|
|
|
|
|
|
|
|
|
|
|
if handler is None: |
|
|
|
if handler is None: |
|
|
|
reraise(exc_type, exc_value, tb) |
|
|
|
reraise(exc_type, exc_value, tb) |
|
|
|
return handler(e) |
|
|
|
return handler(e) |
|
|
|