]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 30 Jun 2023 10:30:58 +0000 (12:30 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 30 Jun 2023 10:44:00 +0000 (12:44 +0200)
- if domain wasn't found domain_data is None
- treat empty JSON replies as errors
- debug level is enough

daemon.py
fba/http/network.py

index 21c1fbff739f91207e209d36fdd4db63a5fb8e6e..674837fcf597075b63f422f78a68af48603a08f6 100755 (executable)
--- 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()
index 20ae9ee9694a854dc124399bc589c656416543a0..d713e921b346d896e1b227444c598b38a3b0ccfc 100644 (file)
@@ -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