From 247d71db7ada8d2a479298048abee81eaf704e66 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 24 Jun 2024 16:55:19 -0700 Subject: [PATCH] fix(utils.py): fix exception_mapping check for errors If exception already mapped - don't attach traceback to it --- litellm/exceptions.py | 16 +++++----------- litellm/utils.py | 4 ++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/litellm/exceptions.py b/litellm/exceptions.py index 9674d48b120..98b51927841 100644 --- a/litellm/exceptions.py +++ b/litellm/exceptions.py @@ -9,10 +9,11 @@ ## LiteLLM versions of the OpenAI Exception Types -import openai -import httpx from typing import Optional +import httpx +import openai + class AuthenticationError(openai.AuthenticationError): # type: ignore def __init__( @@ -658,15 +659,8 @@ class APIResponseValidationError(openai.APIResponseValidationError): # type: ig class OpenAIError(openai.OpenAIError): # type: ignore - def __init__(self, original_exception): - self.status_code = original_exception.http_status - super().__init__( - http_body=original_exception.http_body, - http_status=original_exception.http_status, - json_body=original_exception.json_body, - headers=original_exception.headers, - code=original_exception.code, - ) + def __init__(self, original_exception=None): + super().__init__() self.llm_provider = "openai" diff --git a/litellm/utils.py b/litellm/utils.py index 0849ba3a26d..ce66d0fbb0c 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -5914,6 +5914,7 @@ def exception_type( ) else: # if no status code then it is an APIConnectionError: https://github.com/openai/openai-python#handling-errors + # exception_mapping_worked = True raise APIConnectionError( message=f"APIConnectionError: {exception_provider} - {message}", llm_provider=custom_llm_provider, @@ -7460,6 +7461,9 @@ def exception_type( if exception_mapping_worked: raise e else: + for error_type in litellm.LITELLM_EXCEPTION_TYPES: + if isinstance(e, error_type): + raise e # it's already mapped raise APIConnectionError( message="{}\n{}".format(original_exception, traceback.format_exc()), llm_provider="",