From 7b9fed841bba9e7fc390603db7bc789f4829d627 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Wed, 27 Feb 2019 09:04:57 +0100 Subject: Manage exception with maintdb command --- MgaRepo/commands/maintdb.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/MgaRepo/commands/maintdb.py b/MgaRepo/commands/maintdb.py index 83621b1..ad830b4 100644 --- a/MgaRepo/commands/maintdb.py +++ b/MgaRepo/commands/maintdb.py @@ -34,8 +34,16 @@ def maintdb(maintdb_args): host = config.get("maintdb", "host", "maintdb.mageia.org") if (maintdb_args[0] == 'get' and len(maintdb_args)>=2): import urllib.request - page=urllib.request.urlopen('http://'+host+'/'+maintdb_args[1]) - rep = page.read().decode('utf8') + try: + page=urllib.request.urlopen('http://'+host+'/'+maintdb_args[1]) + rep = page.read().decode('utf8') + except urllib.error.HTTPError as e: + if e.code == 404 : + rep = "There is no package named {}".format(maintdb_args[1]) + else: + rep = e.reason + except Exception as e: + rep = "Error trying to query the database : {}. Have you active Internet connection?".format(e.reason) print(rep) else: maintdb_helper = get_helper("maintdb") -- cgit v1.2.1