fix: code result included "error" field

pull/22392/head
quicksandzn 10 months ago
parent 9823edd3a2
commit abefc39bcb

@ -45,17 +45,13 @@ class TemplateTransformer(ABC):
result_str = cls.extract_result_str_from_response(response) result_str = cls.extract_result_str_from_response(response)
result = json.loads(result_str) result = json.loads(result_str)
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
raise ValueError(f"Failed to parse JSON response: {str(e)}. Response content: {result_str[:200]}...") raise ValueError(f"Failed to parse JSON response: {str(e)}.")
except ValueError as e: except ValueError as e:
# Re-raise ValueError from extract_result_str_from_response # Re-raise ValueError from extract_result_str_from_response
raise e raise e
except Exception as e: except Exception as e:
raise ValueError(f"Unexpected error during response transformation: {str(e)}") raise ValueError(f"Unexpected error during response transformation: {str(e)}")
# Check if the result contains an error
if isinstance(result, dict) and "error" in result:
raise ValueError(f"JavaScript execution error: {result['error']}")
if not isinstance(result, dict): if not isinstance(result, dict):
raise ValueError(f"Result must be a dict, got {type(result).__name__}") raise ValueError(f"Result must be a dict, got {type(result).__name__}")
if not all(isinstance(k, str) for k in result): if not all(isinstance(k, str) for k in result):

Loading…
Cancel
Save