From bee6c9a4720a614408f64754e547ebe5c1697393 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Sat, 27 May 2023 10:07:00 +0200
Subject: [PATCH] Continued: - ops, I need to check again API response code -
 also variable 'json' isn't here, need to take 'res.json()' directly

---
 fba.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fba.py b/fba.py
index b5d536e..bc972f3 100644
--- a/fba.py
+++ b/fba.py
@@ -399,11 +399,14 @@ def get_peers(domain: str, software: str) -> list:
         if not res.ok or res.status_code >= 400:
             res = reqto.get(f"https://{domain}/api/v3/site", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
 
-            if "federated_instances" in json and "linked" in json["federated_instances"]:
+            if not res.ok or res.status_code >= 400:
+                print("WARNING: Could not reach any JSON API:", domain)
+                update_last_error(domain, res)
+            elif "federated_instances" in res.json() and "linked" in res.json()["federated_instances"]:
                 # NOISY-DEBUG: print("DEBUG: Found federated_instances", domain)
-                peers = json["federated_instances"]["linked"] + json["federated_instances"]["allowed"] + json["federated_instances"]["blocked"]
+                peers = res.json()["federated_instances"]["linked"] + res.json()["federated_instances"]["allowed"] + res.json()["federated_instances"]["blocked"]
             else:
-                print("WARNING: Could not reach any JSON API:", domain)
+                print("WARNING: JSON response does not contain 'federated_instances':", domain)
                 update_last_error(domain, res)
         else:
             # NOISY-DEBUG: print("DEBUG:Querying API was successful:", domain, len(res.json()))
-- 
2.39.5