From: Michael Tremer Date: Wed, 14 Jan 2026 14:50:40 +0000 (+0000) Subject: dbl: Always catch 404 and return None X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8243530dfe8417f8d339cda18ac23658673d4fd;p=ipfire.org.git dbl: Always catch 404 and return None Signed-off-by: Michael Tremer --- diff --git a/src/backend/dbl.py b/src/backend/dbl.py index 39b42f57..ce19b219 100644 --- a/src/backend/dbl.py +++ b/src/backend/dbl.py @@ -53,9 +53,17 @@ class DBL(Object): body = json.dumps(body) # Send the request - response = await self.backend.http_client.fetch( - url, headers=headers, body=body, **kwargs, - ) + try: + response = await self.backend.http_client.fetch( + url, headers=headers, body=body, **kwargs, + ) + + # Return nothing if we received 404 + except tornado.httpclient.HTTPClientError as e: + if e.code == 404: + return + + raise e # Decode the response return json.loads(response.body) @@ -69,18 +77,11 @@ class DBL(Object): return [List(self.backend, **list) for list in response] async def get_list(self, slug): - try: - response = await self._fetch("/lists/%s" % slug) - - # Return nothing if we received 404 - except tornado.httpclient.HTTPClientError as e: - if e.code == 404: - return - - raise e + response = await self._fetch("/lists/%s" % slug) # Return the list - return List(self.backend, **response) + if response: + return List(self.backend, **response) # Reports @@ -88,18 +89,11 @@ class DBL(Object): """ Fetches a report """ - try: - response = await self._fetch("/reports/%s" % id) - - # Return nothing if we received 404 - except tornado.httpclient.HTTPClientError as e: - if e.code == 404: - return - - raise e + response = await self._fetch("/reports/%s" % id) # Return the report - return Report(self.backend, **response) + if response: + return Report(self.backend, **response) # Search!