From 27a8164c0bb555fe92c3c2ab0dbde45e12ba34e5 Mon Sep 17 00:00:00 2001 From: Andrej Manduch Date: Nov 28 2023 00:11:41 +0000 Subject: Dedicated 404 exception Issue is that without dedicated exception classes it's hard to determine what exactly happened. This commit adds HTTP404Exception, and BrokenJSONException class. It's usefull when you wanna tell if request just failed or that specific content doesn't exists Signed-off-by: Andrej Manduch --- diff --git a/libpagure/libpagure.py b/libpagure/libpagure.py index 11965b9..1df3d30 100644 --- a/libpagure/libpagure.py +++ b/libpagure/libpagure.py @@ -11,6 +11,11 @@ except ImportError: # Python 2 import httplib as http_client +class HTTP404Exception(Exception): + pass + +class BrokenJSONException(Exception): + pass class NullHandler(logging.Handler): # Null logger to avoid spurious messages @@ -92,15 +97,13 @@ class Pagure(object): ) if req.status_code == 404: - # TODO: use a dedicated error class - raise Exception("404, {} not found".format(url)) + raise HTTP404Exception("404, {} not found".format(url)) try: output = req.json() except Exception as err: LOG.debug(req.text) - # TODO: use a dedicated error class - raise Exception("Error while decoding JSON: {0}".format(err)) + raise BrokenJSONException("Error while decoding JSON: {0}".format(err)) if req.status_code != 200: LOG.error(output)