diff --git a/backend/app/services/llm_service.py b/backend/app/services/llm_service.py index ebbdaf36..19e26fe2 100755 --- a/backend/app/services/llm_service.py +++ b/backend/app/services/llm_service.py @@ -300,9 +300,17 @@ class LLMService: except Exception as e: # Fallback for OpenAI and other non-Google errors last_error = e - error_message = str(e).lower() + # Debug: capture full exception details + exc_type = type(e).__name__ + exc_module = type(e).__module__ + exc_str = str(e) + exc_repr = repr(e) + exc_args = getattr(e, 'args', ()) + exc_dict = getattr(e, '__dict__', {}) - logger.warning(f"LLM attempt {attempt_num}/{max_retries} failed: {str(e)}") + logger.warning(f"LLM attempt {attempt_num}/{max_retries} failed - Type: {exc_module}.{exc_type}, str: '{exc_str}', repr: {exc_repr}, args: {exc_args}, dict: {exc_dict}") + + error_message = exc_str.lower() if exc_str else exc_repr.lower() # Check if this is a retryable error (API internal errors, rate limiting, etc.) if ("500" in error_message or @@ -331,7 +339,8 @@ class LLMService: error_msg = getattr(last_error, 'message', str(last_error)) or str(last_error) or repr(last_error) error_detail = f"[Google API {error_code}] {error_msg}" else: - error_detail = str(last_error) + # Use repr if str is empty + error_detail = str(last_error) or repr(last_error) or f"{type(last_error).__module__}.{type(last_error).__name__}: {getattr(last_error, 'args', ())}" logger.error(f"LLM content generation failed after {max_retries} attempts. Final error: {error_detail}") raise LLMServiceError(f"Error generating content: {error_detail}")