Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

feat: imporve error handling

Amr Awad27e95c0f1c45
diff --git a/modules/sfp_bingsearch.py b/modules/sfp_bingsearch.py
index 04dd639c..fdaa16cd 100644
--- a/modules/sfp_bingsearch.py
+++ b/modules/sfp_bingsearch.py
@@ -90,10 +90,14 @@ class sfp_bingsearch(SpiderFootPlugin):
timeout=self.opts["_fetchtimeout"],
useragent=self.opts["_useragent"],
)
- evt = SpiderFootEvent(
- "SEARCH_ENGINE_WEB_CONTENT", response["content"], self.__name__, event
- )
- self.notifyListeners(evt)
+ if response['status'] == 'OK':
+ evt = SpiderFootEvent(
+ "SEARCH_ENGINE_WEB_CONTENT", response["content"], self.__name__, event
+ )
+ self.notifyListeners(evt)
+ else:
+ self.sf.error("Failed to fetch bing web search URL", exception=False)
+
# End of sfp_bingsearch class
diff --git a/modules/sfp_bingsharedip.py b/modules/sfp_bingsharedip.py
index 68ba8904..514f18c8 100644
--- a/modules/sfp_bingsharedip.py
+++ b/modules/sfp_bingsharedip.py
@@ -170,13 +170,16 @@ class sfp_bingsharedip(SpiderFootPlugin):
timeout=self.opts["_fetchtimeout"],
useragent=self.opts["_useragent"],
)
- evt = SpiderFootEvent(
- "SEARCH_ENGINE_WEB_CONTENT",
- response["content"],
- self.__name__,
- event,
- )
- self.notifyListeners(evt)
+ if response['status'] == 'OK':
+ evt = SpiderFootEvent(
+ "SEARCH_ENGINE_WEB_CONTENT",
+ response["content"],
+ self.__name__,
+ event,
+ )
+ self.notifyListeners(evt)
+ else:
+ self.sf.error("Failed to fetch bing web search URL", exception=False)
# End of sfp_bingsharedip class
diff --git a/sflib.py b/sflib.py
index 5bae66be..bd67a27f 100644
--- a/sflib.py
+++ b/sflib.py
@@ -1325,11 +1325,8 @@ class SpiderFoot:
headers={"Ocp-Apim-Subscription-Key": opts["api_key"]},
)
- if response is None:
- message = "Failed to talk to Bing API, status code: %s, response: %s".format(
- response.status_code, response.text
- )
- self.error(message)
+ if response['status'] != 'OK':
+ self.error("Failed to get a valid response from bing API", exception=False)
return None
response_json = json.loads(response['content'])