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/center.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'cli/objects/center.py') diff --git a/cli/objects/center.py b/cli/objects/center.py index 80e5e3e..9948254 100644 --- a/cli/objects/center.py +++ b/cli/objects/center.py @@ -23,7 +23,10 @@ class OgCenter(): payload = {'name': parsed_args.name} if parsed_args.desc: payload['comment'] = parsed_args.desc - rest.post('/center/add', payload=payload) + res = rest.post('/center/add', payload=payload) + if not res: + return 1 + return 0 @staticmethod def update_center(rest, args): @@ -48,7 +51,10 @@ class OgCenter(): } if parsed_args.comment: payload['comment'] = parsed_args.comment - rest.post('/center/update', payload=payload) + res = rest.post('/center/update', payload=payload) + if not res: + return 1 + return 0 @staticmethod def delete_center(rest, args): @@ -60,4 +66,7 @@ class OgCenter(): help='center id in database') parsed_args = parser.parse_args(args) payload = {'id': parsed_args.id} - rest.post('/center/delete', payload=payload) + res = rest.post('/center/delete', payload=payload) + if not res: + return 1 + return 0 -- cgit v1.2.3-18-g5258