diff options
Diffstat (limited to 'cli/cli.py')
-rw-r--r-- | cli/cli.py | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -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}") |