From 3d0aff3d1d47a053a678ecbec69d585cf1bbb275 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Fri, 8 Nov 2024 10:06:00 +0100 Subject: cli: ensure the program returns 0 on success and 1 on error propagate a returncode in each operation and make it the returncode of the program. Prevent sys.exit calls in post(), get() and delete() request handlers to enable cleanup code and error handling. Keep a basic error log inside the request functions if the connection can't be established or if the response contains an error code. --- cli/objects/poweroff.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'cli/objects/poweroff.py') diff --git a/cli/objects/poweroff.py b/cli/objects/poweroff.py index af309bf..ab14b0d 100644 --- a/cli/objects/poweroff.py +++ b/cli/objects/poweroff.py @@ -36,8 +36,8 @@ class OgPoweroff(): help='Specific client IP') parsed_args = parser.parse_args(args) - r = rest.get('/scopes') - scopes = r.json() + res = rest.get('/scopes') + scopes = res.json() ips = set() for center in parsed_args.center_id: @@ -51,7 +51,10 @@ class OgPoweroff(): if not ips: print("Missing --client-ip, or --room-id/--center-id. No clients provided.") - return None + return 1 payload = {'clients': list(ips)} - r = rest.post('/poweroff', payload=payload) + res = rest.post('/poweroff', payload=payload) + if not res: + return 1 + return 0 -- cgit v1.2.3-18-g5258