fix(utils.py): fix exception_mapping check for errors

If exception already mapped - don't attach traceback to it
This commit is contained in:
Krrish Dholakia 2024-06-24 16:55:19 -07:00
parent 70a605b3cc
commit 123477b55a
2 changed files with 9 additions and 11 deletions

View file

@ -9,10 +9,11 @@
## LiteLLM versions of the OpenAI Exception Types ## LiteLLM versions of the OpenAI Exception Types
import openai
import httpx
from typing import Optional from typing import Optional
import httpx
import openai
class AuthenticationError(openai.AuthenticationError): # type: ignore class AuthenticationError(openai.AuthenticationError): # type: ignore
def __init__( def __init__(
@ -658,15 +659,8 @@ class APIResponseValidationError(openai.APIResponseValidationError): # type: ig
class OpenAIError(openai.OpenAIError): # type: ignore class OpenAIError(openai.OpenAIError): # type: ignore
def __init__(self, original_exception): def __init__(self, original_exception=None):
self.status_code = original_exception.http_status super().__init__()
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,
)
self.llm_provider = "openai" self.llm_provider = "openai"

View file

@ -5914,6 +5914,7 @@ def exception_type(
) )
else: else:
# if no status code then it is an APIConnectionError: https://github.com/openai/openai-python#handling-errors # if no status code then it is an APIConnectionError: https://github.com/openai/openai-python#handling-errors
# exception_mapping_worked = True
raise APIConnectionError( raise APIConnectionError(
message=f"APIConnectionError: {exception_provider} - {message}", message=f"APIConnectionError: {exception_provider} - {message}",
llm_provider=custom_llm_provider, llm_provider=custom_llm_provider,
@ -7460,6 +7461,9 @@ def exception_type(
if exception_mapping_worked: if exception_mapping_worked:
raise e raise e
else: else:
for error_type in litellm.LITELLM_EXCEPTION_TYPES:
if isinstance(e, error_type):
raise e # it's already mapped
raise APIConnectionError( raise APIConnectionError(
message="{}\n{}".format(original_exception, traceback.format_exc()), message="{}\n{}".format(original_exception, traceback.format_exc()),
llm_provider="", llm_provider="",