From 7b2c38068e773872c49b19578bdf7e9be7226e2f Mon Sep 17 00:00:00 2001 From: Wenjing Yu Date: Tue, 22 Jul 2025 13:29:31 -0700 Subject: [PATCH] Added missing field to handle error code --- app/exceptions/exceptions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/exceptions/exceptions.py b/app/exceptions/exceptions.py index 112527f..ca2e516 100644 --- a/app/exceptions/exceptions.py +++ b/app/exceptions/exceptions.py @@ -42,7 +42,24 @@ class ProviderAPIException(BaseForgeException): """Exception raised when a provider API error occurs.""" def __init__(self, provider_name: str, error_code: int, error_message: str): - super().__init__(f"Provider {provider_name} API error: {error_code} {error_message}") + """Initialize the exception and persist error details for downstream handling. + + Many parts of the codebase (e.g. the Claude Code routes) rely on the + presence of the ``error_code`` and ``error_message`` attributes to + construct a well-formed error response. Without setting these instance + attributes an ``AttributeError`` is raised when the exception is caught + and introspected, masking the original provider failure. Persisting the + values here guarantees that the original error information is available + to any error-handling middleware. + """ + self.provider_name = provider_name + self.error_code = error_code + self.error_message = error_message + + # Compose the base exception message for logging / debugging purposes. + super().__init__( + f"Provider {provider_name} API error: {error_code} {error_message}" + ) class BaseInvalidRequestException(BaseForgeException):