Skip to content

Commit

Permalink
Merge pull request #31 from veryfi/fix_404
Browse files Browse the repository at this point in the history
Pass 404 and other errors
  • Loading branch information
manycoding authored Mar 15, 2022
2 parents 991c115 + cc0fb01 commit 332e77e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGES
=======

3.0.0
-----
* Return proper 404 and other errors

3.0.0
-----
* Use v8 by default, lower timeout
Expand Down
15 changes: 15 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,18 @@ def test_bad_request():

with pytest.raises(BadRequest, match="400, Bad or missing parameters") as e:
raise VeryfiClientError.from_response(response)


@responses.activate
def test_not_found():
url = f"{Client.BASE_URL}v7/partner/documents"
responses.add(
responses.PUT,
url,
json={"status": "fail", "error": "Document not found"},
status=404,
)
response = requests.put(url)

with pytest.raises(VeryfiClientError, match="404, Document not found") as e:
raise VeryfiClientError.from_response(response)
14 changes: 2 additions & 12 deletions veryfi/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,8 @@ def from_response(raw_response):
'error': 'Human readable error description.'
}
"""
json_response = raw_response.json()
# TODO Add Error Codes to API response
# code = error_info.get("code", "")

try:
error_cls = _error_map[raw_response.status_code]
except KeyError:
raise NotImplementedError(
"Unknown error Please contact customer support at support@veryfi.com."
)
else:
return error_cls(raw_response, **raw_response.json())
error_cls = _error_map.get(raw_response.status_code) or VeryfiClientError
return error_cls(raw_response, **raw_response.json())


class UnauthorizedAccessToken(VeryfiClientError):
Expand Down

0 comments on commit 332e77e

Please sign in to comment.