From c3c9ba4a72dd3a7560791692b7918c7148409919 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 13 Aug 2019 14:59:12 +0530 Subject: [PATCH] Show error message elegantly --- ungleich_pay.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ungleich_pay.py b/ungleich_pay.py index b5fb711..bfdcc6b 100644 --- a/ungleich_pay.py +++ b/ungleich_pay.py @@ -1,5 +1,6 @@ import urllib.request import json +import sys from pyotp import TOTP UNGLEICH_PAY_SERVER_URL = "https://pay.ungleich.ch" @@ -45,6 +46,13 @@ class ungleichPay(object): "token": TOTP(args.seed).now(), "Accept": "application/json" }) - response = urllib.request.urlopen(req) + try: + response = urllib.request.urlopen(req) + except urllib.error.HTTPError as err: + print(str(err)) + sys.exit(1) + except urllib.error.URLError as uerr: + print(str(uerr)) + sys.exit(2) response_json = json.loads(response.read().decode('utf-8')) print(response_json["data"])