Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion monzo/httpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def _perform_request(
with response as fh:
content += fh.read().decode('utf-8')
except HTTPError as error:
raise MONZO_ERROR_MAP[error.code]() from error
exception_cls = MONZO_ERROR_MAP.get(error.code, MonzoGeneralError)
raise exception_cls() from error
return {
'code': response.code,
'headers': response.headers,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_httpio_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from unittest.mock import patch
from urllib.error import HTTPError

import pytest

from monzo.exceptions import MonzoGeneralError
from monzo.httpio import HttpIO


def test_unknown_status_code_raises_monzogeneralerror():
http = HttpIO('https://example.com')
error = HTTPError(url='https://example.com/test', code=418, msg='teapot', hdrs=None, fp=None)
with patch('monzo.httpio.urlopen', side_effect=error):
with pytest.raises(MonzoGeneralError):
http.get('/test')