mirror of https://git.48k.eu/ogcli/
cli: improve HTTP status code error logging
Use a different message for each status code when the request is not successful.master
parent
4b77e1bca8
commit
12d965ce1c
24
cli/cli.py
24
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}")
|
||||
|
|
Loading…
Reference in New Issue