fix(utils.py): return traceback on unmapped exception error

Fixes https://github.com/BerriAI/litellm/issues/4201
This commit is contained in:
Krrish Dholakia 2024-06-14 15:08:01 -07:00
parent ab3ece37c0
commit 2732ff5d56
4 changed files with 16 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -8420,7 +8420,7 @@ def exception_type(
extra_information = _add_key_name_and_team_to_alert( extra_information = _add_key_name_and_team_to_alert(
request_info=extra_information, metadata=_metadata request_info=extra_information, metadata=_metadata
) )
except: except Exception:
# DO NOT LET this Block raising the original exception # DO NOT LET this Block raising the original exception
pass pass
@ -9956,6 +9956,9 @@ def exception_type(
response=original_exception.response, response=original_exception.response,
) )
else: # ensure generic errors always return APIConnectionError= else: # ensure generic errors always return APIConnectionError=
"""
For unmapped exceptions - raise the exception with traceback - https://github.com/BerriAI/litellm/issues/4201
"""
exception_mapping_worked = True exception_mapping_worked = True
if hasattr(original_exception, "request"): if hasattr(original_exception, "request"):
raise APIConnectionError( raise APIConnectionError(
@ -9966,7 +9969,9 @@ def exception_type(
) )
else: else:
raise APIConnectionError( raise APIConnectionError(
message=f"{str(original_exception)}", message="{}\n{}".format(
str(original_exception), traceback.format_exc()
),
llm_provider=custom_llm_provider, llm_provider=custom_llm_provider,
model=model, model=model,
request=httpx.Request( request=httpx.Request(
@ -9992,7 +9997,15 @@ def exception_type(
if exception_mapping_worked: if exception_mapping_worked:
raise e raise e
else: else:
raise original_exception raise APIConnectionError(
message="{}\n{}".format(original_exception, traceback.format_exc()),
llm_provider="",
model="",
request=httpx.Request(
method="POST",
url="https://www.litellm.ai/",
),
)
def get_or_generate_uuid(): def get_or_generate_uuid():