Skip to content

Commit 3614101

Browse files
authored
Display API error message if available (#338)
* Display API error message if available * Allow catch-all for error handling
1 parent f885ca8 commit 3614101

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

protonvpn_cli/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ def call_api(endpoint, json_format=True, handle_errors=True):
5555
try:
5656
response.raise_for_status()
5757
except requests.exceptions.HTTPError:
58+
try:
59+
error_message = response.json()['Error']
60+
except: # noqa
61+
error_message = "Unknown error"
5862
print(
5963
"[!] There was an error with accessing the ProtonVPN API.\n"
6064
"[!] Please make sure your connection is working properly!\n"
61-
"[!] HTTP Error Code: {0}".format(response.status_code)
65+
"[!] HTTP Error Code: {0}\n"
66+
"[!] {1}".format(response.status_code, error_message)
6267
)
6368
logger.debug("Bad Return Code: {0}".format(response.status_code))
6469
sys.exit(1)

0 commit comments

Comments
 (0)