Skip to content

Commit

Permalink
Merge pull request #17 from AdCombo/16-fix-format-http-exception
Browse files Browse the repository at this point in the history
fix format_http_exception error
  • Loading branch information
Znbiz authored Apr 23, 2020
2 parents 7558e71 + fe52a1c commit 17e4a23
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flask_combo_jsonapi/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def format_http_exception(ex):
code = getattr(ex, 'code', None)
try:
status = int(code)
except TypeError:
except (TypeError, ValueError):
return

api_ex = STATUS_MAP.get(status)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from unittest.mock import Mock

from flask_combo_jsonapi import JsonApiException
from flask_combo_jsonapi.errors import format_http_exception


def test_format_http_exception__value_error():
ex = Mock()
ex.code = 'f405'

assert format_http_exception(ex) is None


def test_format_http_exception__type_error():
ex = Mock()
ex.code = 'not_int'

assert format_http_exception(ex) is None


def test_format_http_exception__success():
ex = Mock()
ex.code = 400

res = format_http_exception(ex)

assert isinstance(res, JsonApiException)
assert res.status == '400'

0 comments on commit 17e4a23

Please sign in to comment.