Skip to content

Commit 17e4a23

Browse files
authored
Merge pull request #17 from AdCombo/16-fix-format-http-exception
fix format_http_exception error
2 parents 7558e71 + fe52a1c commit 17e4a23

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

flask_combo_jsonapi/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def format_http_exception(ex):
3030
code = getattr(ex, 'code', None)
3131
try:
3232
status = int(code)
33-
except TypeError:
33+
except (TypeError, ValueError):
3434
return
3535

3636
api_ex = STATUS_MAP.get(status)

tests/test_errors.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from unittest.mock import Mock
2+
3+
from flask_combo_jsonapi import JsonApiException
4+
from flask_combo_jsonapi.errors import format_http_exception
5+
6+
7+
def test_format_http_exception__value_error():
8+
ex = Mock()
9+
ex.code = 'f405'
10+
11+
assert format_http_exception(ex) is None
12+
13+
14+
def test_format_http_exception__type_error():
15+
ex = Mock()
16+
ex.code = 'not_int'
17+
18+
assert format_http_exception(ex) is None
19+
20+
21+
def test_format_http_exception__success():
22+
ex = Mock()
23+
ex.code = 400
24+
25+
res = format_http_exception(ex)
26+
27+
assert isinstance(res, JsonApiException)
28+
assert res.status == '400'

0 commit comments

Comments
 (0)