Skip to content

Commit 7fa674a

Browse files
author
Antti Myyrä
committed
chore(errors): Support new error format along the old one
1 parent 1532055 commit 7fa674a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

upcloud_api/api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ def __error_middleware(self, res, res_json):
8686
"""
8787
Middleware that raises an exception when HTTP statuscode is an error code.
8888
"""
89-
if res.status_code in [400, 401, 402, 403, 404, 405, 406, 409]:
89+
if res.status_code >= 400:
90+
if res_json.get('type'):
91+
raise UpCloudAPIError(
92+
error_code=res_json.get('title'),
93+
error_message=f'Details: {json.dumps(res_json)}',
94+
)
95+
9096
err_dict = res_json.get('error', {})
9197
raise UpCloudAPIError(
9298
error_code=err_dict.get('error_code'), error_message=err_dict.get('error_message')

0 commit comments

Comments
 (0)