Skip to content

Commit 2d77f8f

Browse files
authored
Merge pull request #527 from orishoshan/master
Propagate exceptions from the flask-restplus handler if propagate exceptions is enabled
2 parents a8f3582 + cba8450 commit 2d77f8f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

flask_restplus/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,13 @@ def handle_error(self, e):
592592
'''
593593
got_request_exception.send(current_app._get_current_object(), exception=e)
594594

595+
if not isinstance(e, HTTPException) and current_app.propagate_exceptions:
596+
exc_type, exc_value, tb = sys.exc_info()
597+
if exc_value is e:
598+
raise
599+
else:
600+
raise e
601+
595602
include_message_in_response = current_app.config.get("ERROR_INCLUDE_MESSAGE", True)
596603
default_data = {}
597604

tests/test_errors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ def get(self):
291291

292292
app.config['PROPAGATE_EXCEPTIONS'] = True
293293

294-
response = client.get('/api/test/')
295-
assert response.status_code == 500
296-
assert response.content_type == 'application/json'
297-
298-
data = json.loads(response.data.decode('utf8'))
299-
assert 'message' in data
294+
# From the Flask docs:
295+
# PROPAGATE_EXCEPTIONS
296+
# Exceptions are re-raised rather than being handled by the app’s error handlers.
297+
# If not set, this is implicitly true if TESTING or DEBUG is enabled.
298+
with pytest.raises(Exception):
299+
client.get('/api/test/')
300300

301301
def test_custom_default_errorhandler(self, app, client):
302302
api = restplus.Api(app)

0 commit comments

Comments
 (0)