Skip to content

Commit

Permalink
fix(agent): Suppress creation of err logs for req failures
Browse files Browse the repository at this point in the history
This is possible by setting http_status_code to < 500. Using custom
status code 420 for this purpose.
  • Loading branch information
balamurali27 committed Jan 20, 2025
1 parent 62f834a commit 4ef2a80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion press/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from frappe.utils.password import get_decrypted_password
from requests.exceptions import HTTPError

from press.exceptions import AgentHTTPError
from press.utils import get_mariadb_root_password, log_error, sanitize_config

if TYPE_CHECKING:
Expand Down Expand Up @@ -777,7 +778,7 @@ def request(self, method, path, data=None, files=None, agent_job=None, raises=Tr
output = "\n\n".join([json_response.get("output", ""), json_response.get("traceback", "")])
if output == "\n\n":
output = json.dumps(json_response, indent=2, sort_keys=True)
raise HTTPError(
raise AgentHTTPError(

Check warning on line 781 in press/agent.py

View check run for this annotation

Codecov / codecov/patch

press/agent.py#L781

Added line #L781 was not covered by tests
f"{response.status_code} {response.reason}\n\n{output}",
response=response,
)
Expand Down
9 changes: 9 additions & 0 deletions press/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from frappe.exceptions import ValidationError
from requests import HTTPError


class CentralServerNotSet(ValidationError):
Expand Down Expand Up @@ -55,3 +56,11 @@ class SiteAlreadyArchived(ValidationError):

class InactiveDomains(ValidationError):
pass


class AgentHTTPError(HTTPError):
def __init__(
self, *args, request=None, response=None, status_code=555
): # custom status_code exception to suppress err logs
self.http_status_code = status_code
super().__init__(*args, request=request, response=response)

Check warning on line 66 in press/exceptions.py

View check run for this annotation

Codecov / codecov/patch

press/exceptions.py#L65-L66

Added lines #L65 - L66 were not covered by tests

0 comments on commit 4ef2a80

Please sign in to comment.