Skip to content

Commit f05aba1

Browse files
author
Valeriy Mukhtarulin
committed
Pass 404 and other errors
1 parent 991c115 commit f05aba1

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGES
22
=======
33

4+
3.0.0
5+
-----
6+
* Return proper 404 error
7+
48
3.0.0
59
-----
610
* Use v8 by default, lower timeout

tests/test_errors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ def test_bad_request():
1919

2020
with pytest.raises(BadRequest, match="400, Bad or missing parameters") as e:
2121
raise VeryfiClientError.from_response(response)
22+
23+
24+
@responses.activate
25+
def test_not_found():
26+
url = f"{Client.BASE_URL}v7/partner/documents"
27+
responses.add(
28+
responses.PUT,
29+
url,
30+
json={"status": "fail", "error": "Document not found"},
31+
status=404,
32+
)
33+
response = requests.put(url)
34+
35+
with pytest.raises(VeryfiClientError, match="404, Document not found") as e:
36+
raise VeryfiClientError.from_response(response)

veryfi/errors.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,8 @@ def from_response(raw_response):
2020
'error': 'Human readable error description.'
2121
}
2222
"""
23-
json_response = raw_response.json()
24-
# TODO Add Error Codes to API response
25-
# code = error_info.get("code", "")
26-
27-
try:
28-
error_cls = _error_map[raw_response.status_code]
29-
except KeyError:
30-
raise NotImplementedError(
31-
"Unknown error Please contact customer support at support@veryfi.com."
32-
)
33-
else:
34-
return error_cls(raw_response, **raw_response.json())
23+
error_cls = _error_map.get(raw_response.status_code) or VeryfiClientError
24+
return error_cls(raw_response, **raw_response.json())
3525

3626

3727
class UnauthorizedAccessToken(VeryfiClientError):
@@ -54,6 +44,10 @@ class InternalError(VeryfiClientError):
5444
pass
5545

5646

47+
class InternalError(VeryfiClientError):
48+
pass
49+
50+
5751
_error_map = {
5852
400: BadRequest,
5953
401: UnauthorizedAccessToken,

0 commit comments

Comments
 (0)