From 8b494948553a823d7f787da7d12830b30b6896c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 30 Jun 2023 12:30:58 +0200 Subject: [PATCH] Continued: - if domain wasn't found domain_data is None - treat empty JSON replies as errors - debug level is enough --- daemon.py | 3 +++ fba/http/network.py | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/daemon.py b/daemon.py index 21c1fbf..674837f 100755 --- a/daemon.py +++ b/daemon.py @@ -328,6 +328,9 @@ def rss(request: Request, domain: str): database.cursor.execute("SELECT * FROM instances WHERE domain = ? LIMIT 1", [domain]) domain_data = database.cursor.fetchone() + if domain_data is None: + raise HTTPException(status_code=404, detail=f"domain='{domain}' not found") + # Format timestamps format = config.get("timestamp_format") instance = dict() diff --git a/fba/http/network.py b/fba/http/network.py index 20ae9ee..d713e92 100644 --- a/fba/http/network.py +++ b/fba/http/network.py @@ -82,11 +82,11 @@ def post_json_api(domain: str, path: str, data: str = "", headers: dict = dict() cookies=cookies.get_all(domain) if cookies.has(domain) else dict() ) - logger.info("Parsing JSON response from domain='%s',path='%s' ...", domain, path) + logger.debug("Parsing JSON response from domain='%s',path='%s' ...", domain, path) json_reply["json"] = json_from_response(response) logger.debug("response.ok='%s',response.status_code=%d,json_reply[]='%s'", response.ok, response.status_code, type(json_reply)) - if not response.ok or response.status_code >= 400: + if not response.ok or response.status_code >= 400 or len(json_reply["json"]) == 0: logger.warning("Cannot query JSON API: domain='%s',path='%s',data()=%d,response.status_code=%d,json_reply[]='%s'", domain, path, len(data), response.status_code, type(json_reply)) json_reply["status_code"] = response.status_code json_reply["error_message"] = response.reason @@ -121,11 +121,11 @@ def fetch_api_url(url: str, timeout: tuple) -> dict: logger.debug("Fetching url='%s' ...", url) response = utils.fetch_url(url, api_headers, timeout) - logger.info("Parsing JSON response from url='%s' ...", url) + logger.debug("Parsing JSON response from url='%s' ...", url) json_reply["json"] = json_from_response(response) logger.debug("response.ok='%s',response.status_code='%s',json_reply[]='%s'", response.ok, response.status_code, type(json_reply)) - if not response.ok or response.status_code >= 400: + if not response.ok or response.status_code >= 400 or len(json_reply["json"]) == 0: logger.warning("Cannot query JSON API: url='%s',response.status_code=%d,json_reply[]='%s'", url, response.status_code, type(json_reply)) json_reply["status_code"] = response.status_code json_reply["error_message"] = response.reason @@ -175,11 +175,11 @@ def get_json_api(domain: str, path: str, headers: dict, timeout: tuple) -> dict: instances.set_last_error(domain, exception) raise exception - logger.info("Parsing JSON response from domain='%s',path='%s' ...", domain, path) + logger.debug("Parsing JSON response from domain='%s',path='%s' ...", domain, path) json_reply["json"] = json_from_response(response) logger.debug("response.ok='%s',response.status_code=%d,json_reply[]='%s'", response.ok, response.status_code, type(json_reply)) - if not response.ok or response.status_code >= 400: + if not response.ok or response.status_code >= 400 or len(json_reply["json"]) == 0: logger.warning("Cannot query JSON API: domain='%s',path='%s',response.status_code=%d,json_reply[]='%s'", domain, path, response.status_code, type(json_reply)) json_reply["status_code"] = response.status_code json_reply["error_message"] = response.reason -- 2.39.5