Merge pull request #199 from p1c2u/fix/flask-error-handler-status-fix

Flask error handler status fix
This commit is contained in:
A 2020-02-18 12:04:13 +00:00 committed by GitHub
commit d4e9fe4e60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -22,10 +22,8 @@ class FlaskOpenAPIErrorsHandler(object):
data = { data = {
'errors': data_errors, 'errors': data_errors,
} }
status = max( data_error_max = max(data_errors, key=lambda x: x['status'])
range(len(data_errors)), status = data_error_max['status']
key=lambda idx: data_errors[idx]['status'],
)
return current_app.response_class( return current_app.response_class(
dumps(data), dumps(data),
status=status, status=status,

View file

@ -45,6 +45,7 @@ class TestFlaskOpenAPIView(object):
result = client.get('/browse/12/') result = client.get('/browse/12/')
assert result.status_code == 415
assert result.json == { assert result.json == {
'errors': [ 'errors': [
{ {
@ -78,6 +79,7 @@ class TestFlaskOpenAPIView(object):
} }
] ]
} }
assert result.status_code == 500
assert result.json == expected_data assert result.json == expected_data
def test_endpoint_error(self, client): def test_endpoint_error(self, client):
@ -97,6 +99,7 @@ class TestFlaskOpenAPIView(object):
} }
] ]
} }
assert result.status_code == 400
assert result.json == expected_data assert result.json == expected_data
def test_valid(self, client): def test_valid(self, client):