summaryrefslogtreecommitdiffstats
path: root/cli/cli.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-12-10 11:26:22 +0100
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-12-10 11:28:44 +0100
commit12d965ce1c1497df6f5d5a63fd562171ce01b9e7 (patch)
treefee2a0c79b920fcee576e712b436e52d547843f2 /cli/cli.py
parent4b77e1bca8ab69ea352a83d8520cb0e390db460f (diff)
cli: improve HTTP status code error logging
Use a different message for each status code when the request is not successful.
Diffstat (limited to 'cli/cli.py')
-rw-r--r--cli/cli.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/cli/cli.py b/cli/cli.py
index 4b808f5..25c1daf 100644
--- a/cli/cli.py
+++ b/cli/cli.py
@@ -26,6 +26,24 @@ import requests
import sys
+def _log_http_status_code(res):
+ if res.status_code == 400:
+ print('Error 400: invalid payload')
+ elif res.status_code == 404:
+ print('Error 404: object not found')
+ elif res.status_code == 405:
+ print('Error 405: method not allowed')
+ elif res.status_code == 409:
+ print('Error 409: object already exists')
+ elif res.status_code == 423:
+ print('Error 423: object in use')
+ elif res.status_code == 501:
+ print('Error 501: cannot connect to database')
+ elif res.status_code == 507:
+ print('Error 500: disk full')
+ else:
+ print(f'Received status code {res.status_code}')
+
class OgREST():
def __init__(self, ip, port, api_token):
self.URL = f'http://{ip}:{port}'
@@ -38,7 +56,7 @@ class OgREST():
json=payload)
if res.status_code != 200:
- print(f"Error: Request to ogServer failed with status code {res.status_code}")
+ _log_http_status_code(res)
return None
except requests.exceptions.RequestException as e:
@@ -54,7 +72,7 @@ class OgREST():
json=payload)
if res.status_code not in {200, 202}:
- print(f"Error: Request to ogServer failed with status code {res.status_code}")
+ _log_http_status_code(res)
return None
except requests.exceptions.RequestException as e:
@@ -69,7 +87,7 @@ class OgREST():
headers=self.HEADERS,
json=payload)
if res.status_code != 200:
- print(f"Error: Request to ogServer failed with status code {res.status_code}")
+ _log_http_status_code(res)
return None
except IOError as e:
print(f"Error: Cannot connect to ogServer: {e}")