mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
fix(exceptions): map 403 to PermissionDeniedError in openai-like mapper
This commit is contained in:
parent
666648d58c
commit
e2e16d7e2d
2 changed files with 14 additions and 3 deletions
|
|
@ -755,12 +755,19 @@ def _map_openai_like_exception(
|
||||||
llm_provider=custom_llm_provider,
|
llm_provider=custom_llm_provider,
|
||||||
model=model,
|
model=model,
|
||||||
)
|
)
|
||||||
elif original_exception.status_code == 401 or original_exception.status_code == 403:
|
elif original_exception.status_code == 401:
|
||||||
raise AuthenticationError(
|
raise AuthenticationError(
|
||||||
message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",
|
message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",
|
||||||
llm_provider=custom_llm_provider,
|
llm_provider=custom_llm_provider,
|
||||||
model=model,
|
model=model,
|
||||||
)
|
)
|
||||||
|
elif original_exception.status_code == 403:
|
||||||
|
raise PermissionDeniedError(
|
||||||
|
message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",
|
||||||
|
llm_provider=custom_llm_provider,
|
||||||
|
model=model,
|
||||||
|
response=getattr(original_exception, "response", None),
|
||||||
|
)
|
||||||
elif original_exception.status_code == 400:
|
elif original_exception.status_code == 400:
|
||||||
raise BadRequestError(
|
raise BadRequestError(
|
||||||
message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",
|
message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",
|
||||||
|
|
|
||||||
|
|
@ -805,7 +805,7 @@ DEVIATIONS_FROM_THE_OPENAI_SHAPE = {
|
||||||
503: UPSTREAM_STATUS_DISCARDED,
|
503: UPSTREAM_STATUS_DISCARDED,
|
||||||
},
|
},
|
||||||
"databricks": {
|
"databricks": {
|
||||||
403: (litellm.AuthenticationError, 401),
|
403: (litellm.PermissionDeniedError, 403),
|
||||||
422: (litellm.BadRequestError, 400),
|
422: (litellm.BadRequestError, 400),
|
||||||
},
|
},
|
||||||
"gemini": {
|
"gemini": {
|
||||||
|
|
@ -1096,7 +1096,11 @@ def test_bedrock_mantle_context_overflow_maps_to_context_window_exceeded():
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"status_code, expected_class",
|
"status_code, expected_class",
|
||||||
[(401, litellm.AuthenticationError), (429, litellm.RateLimitError)],
|
[
|
||||||
|
(401, litellm.AuthenticationError),
|
||||||
|
(403, litellm.PermissionDeniedError),
|
||||||
|
(429, litellm.RateLimitError),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def test_a_base_llm_exception_without_a_provider_branch_maps_by_status_code(
|
def test_a_base_llm_exception_without_a_provider_branch_maps_by_status_code(
|
||||||
status_code, expected_class, quiet_exception_mapping
|
status_code, expected_class, quiet_exception_mapping
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue