From 68f78e1a30b492fc73ada3e4832d3b155d7fb9be Mon Sep 17 00:00:00 2001 From: Alessio <148966056+alessio-locatelli@users.noreply.github.com> Date: Wed, 18 Jun 2025 10:51:19 +0300 Subject: [PATCH] fix: do not fail the CLI when GitLab API return 5xx code --- pr_agent/agent/pr_agent.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pr_agent/agent/pr_agent.py b/pr_agent/agent/pr_agent.py index 0a42a50d..bfe924d6 100644 --- a/pr_agent/agent/pr_agent.py +++ b/pr_agent/agent/pr_agent.py @@ -1,6 +1,9 @@ import shlex from functools import partial +import gitlab +from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR, HTTP_503_SERVICE_UNAVAILABLE + from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler from pr_agent.algo.cli_args import CliArgs @@ -113,7 +116,19 @@ class PRAgent: if notify: notify() - await command2class[action](pr_url, ai_handler=self.ai_handler, args=args).run() + try: + await command2class[action](pr_url, ai_handler=self.ai_handler, args=args).run() + except gitlab.GitlabError as gitlab_error: + # For GitLab 5xx codes see: https://docs.gitlab.com/api/rest/troubleshooting/#status-codes + if gitlab_error.response_code in {HTTP_500_INTERNAL_SERVER_ERROR, HTTP_503_SERVICE_UNAVAILABLE}: + # The problem is likely temporary and not on our side; therefore, do not fail the application. + get_logger().error( + f"Failed to process the command due to a problem on the GitLab API side: {gitlab_error!r}\n" + + "Check https://status.gitlab.com and try again later." + ) + return False + raise + else: return False return True