From 3eae531ca17c3b6780cb870de4d127f6e0b4326e Mon Sep 17 00:00:00 2001 From: Balamurali M Date: Fri, 3 Jan 2025 01:41:02 +0530 Subject: [PATCH] fix(agent): Throw traceback obtained from agent --- press/agent.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/press/agent.py b/press/agent.py index d5a62a475c..2c51604746 100644 --- a/press/agent.py +++ b/press/agent.py @@ -12,6 +12,7 @@ import frappe import requests from frappe.utils.password import get_decrypted_password +from requests.exceptions import HTTPError from press.utils import get_mariadb_root_password, log_error, sanitize_config @@ -781,8 +782,17 @@ def request(self, method, path, data=None, files=None, agent_job=None, raises=Tr json_response = None try: json_response = self.response.json() - if raises: - self.response.raise_for_status() + if raises and self.response.status_code >= 400: + output = ( + f"""{json_response.get("output")} + +{json_response.get("traceback")}""" + or json.dumps(json_response, indent=2, sort_keys=True) + ) + raise HTTPError( + f"{self.response.status_code} {self.response.reason} {output}", + response=self.response, + ) return json_response except Exception: self.handle_request_failure(agent_job, self.response)