From 51c5cc2936ce1507de1c554f4e6ec00dd5877ae9 Mon Sep 17 00:00:00 2001 From: MS Date: Thu, 27 May 2021 13:57:37 +0200 Subject: cli helper function --- cli/bin/libeufin-cli | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cli/bin/libeufin-cli b/cli/bin/libeufin-cli index c2bc5f5d..2499dd6c 100755 --- a/cli/bin/libeufin-cli +++ b/cli/bin/libeufin-cli @@ -12,8 +12,16 @@ from urllib.parse import urljoin from getpass import getpass -def tell_user(resp, withsuccess=False): - if resp.status_code != 200: +# Exit the program according to the HTTP status code that +# was received. +def managed_exit(received_status_code, expected_status_code=200): + if received_status_code != expected_status_code: + sys.exit(1) + sys.exit(0) + + +def tell_user(resp, expected_status_code=200, withsuccess=False): + if resp.status_code != expected_status_code: print(resp.content.decode("utf-8")) return if withsuccess: -- cgit v1.2.3