-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reduce redundancy in error handling (#66)
- Loading branch information
Showing
2 changed files
with
47 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
from json import JSONDecodeError | ||
|
||
from simplejson import JSONDecodeError as SimpleJSONDecodeError | ||
|
||
from varfish_cli.exceptions import RestApiCallException | ||
|
||
|
||
def raise_for_status(response): | ||
if not response.ok: # pragma: no cover | ||
raise RestApiCallException(f"Problem with API call: {response.text}.") | ||
if not response.ok: | ||
try: | ||
msg = "REST API returned status code %d: %s" % ( | ||
response.status_code, | ||
" ".join([" ".join(v) for v in response.json().values()]), | ||
) | ||
except (JSONDecodeError, SimpleJSONDecodeError): | ||
msg = "REST API returned status code %d: %s" % (response.status_code, response.content) | ||
raise RestApiCallException(msg) |