Made outputs response parsing and none handling more reliable.

This commit is contained in:
Lyncoln
2026-10-26 09:51:52 -04:00
parent 8846f467e6
commit 78e5b8fdf7
+44 -18
View File
@@ -1,32 +1,58 @@
import json
import requests
def buildOutput(response, action, outputs):
if hasattr(action, "outputs"):
if response is not None:
try:
try:
if hasattr(response, "content"):
if not response.content:
return outputs
response_data = response.json()
except AttributeError:
else:
if not response:
return outputs
response_data = json.loads(response)
response_objects = [response_data]
while response_objects:
response_object = response_objects.pop()
except (json.JSONDecodeError, requests.exceptions.JSONDecodeError) as error:
print(f"JSON decoding failed during {action.name}: {error}")
return outputs
for key, value, in response_object.items():
if isinstance(value, dict):
response_objects.append(value)
for output_name, response_key in action.outputs.items():
if key == response_key:
outputs[output_name] = value
#print (response_data)
#if response is not None:
# if not response.content:
# return outputs
#
# try:
# response_data = response.json()
# except AttributeError:
# response_data = json.loads(response)
else:
print("No response received"),
if isinstance(response_data, list):
outputs["response_list"] = response_data
return outputs
response_objects = [response_data]
while response_objects:
response_object = response_objects.pop()
for key, value, in response_object.items():
if isinstance(value, dict):
response_objects.append(value)
for output_name, response_key in action.outputs.items():
if key == response_key:
outputs[output_name] = value
#print (response_data)
#else:
# print("No response received"),
return outputs