forked from orbit-oss/flask
Handle BaseExceptions (#2222)
* Handle BaseExceptions * Add test and changes * Make test more idiomatic
This commit is contained in:
parent
19d7e6532f
commit
1d4448abe3
3 changed files with 23 additions and 0 deletions
3
CHANGES
3
CHANGES
|
|
@ -14,6 +14,9 @@ Major release, unreleased
|
||||||
- Change default configuration `JSONIFY_PRETTYPRINT_REGULAR=False`. jsonify()
|
- Change default configuration `JSONIFY_PRETTYPRINT_REGULAR=False`. jsonify()
|
||||||
method returns compressed response by default, and pretty response in
|
method returns compressed response by default, and pretty response in
|
||||||
debug mode.
|
debug mode.
|
||||||
|
- Call `ctx.auto_pop` with the exception object instead of `None`, in the
|
||||||
|
event that a `BaseException` such as `KeyboardInterrupt` is raised in a
|
||||||
|
request handler.
|
||||||
|
|
||||||
Version 0.12.1
|
Version 0.12.1
|
||||||
--------------
|
--------------
|
||||||
|
|
|
||||||
|
|
@ -1991,6 +1991,9 @@ class Flask(_PackageBoundObject):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error = e
|
error = e
|
||||||
response = self.handle_exception(e)
|
response = self.handle_exception(e)
|
||||||
|
except:
|
||||||
|
error = sys.exc_info()[1]
|
||||||
|
raise
|
||||||
return response(environ, start_response)
|
return response(environ, start_response)
|
||||||
finally:
|
finally:
|
||||||
if self.should_ignore_error(error):
|
if self.should_ignore_error(error):
|
||||||
|
|
|
||||||
|
|
@ -791,6 +791,23 @@ def test_error_handling_processing():
|
||||||
assert resp.data == b'internal server error'
|
assert resp.data == b'internal server error'
|
||||||
|
|
||||||
|
|
||||||
|
def test_baseexception_error_handling():
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
app.config['LOGGER_HANDLER_POLICY'] = 'never'
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def broken_func():
|
||||||
|
raise KeyboardInterrupt()
|
||||||
|
|
||||||
|
with app.test_client() as c:
|
||||||
|
with pytest.raises(KeyboardInterrupt):
|
||||||
|
c.get('/')
|
||||||
|
|
||||||
|
ctx = flask._request_ctx_stack.top
|
||||||
|
assert ctx.preserved
|
||||||
|
assert type(ctx._preserved_exc) is KeyboardInterrupt
|
||||||
|
|
||||||
|
|
||||||
def test_before_request_and_routing_errors():
|
def test_before_request_and_routing_errors():
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue