(fix) handle json decode errors for DD exception logging (#6934)

* fix JSONDecodeError

* handle async_log_proxy_authentication_errors

* fix test_async_log_proxy_authentication_errors_get_request
This commit is contained in:
Ishaan Jaff 2024-11-27 14:48:54 -08:00 committed by GitHub
parent 32f21b6af9
commit f5362b1c1a
2 changed files with 130 additions and 3 deletions

View file

@ -891,7 +891,7 @@ class ProxyLogging:
original_exception: Exception,
request: Request,
parent_otel_span: Optional[Any],
api_key: str,
api_key: Optional[str],
):
"""
Handler for Logging Authentication Errors on LiteLLM Proxy
@ -905,9 +905,13 @@ class ProxyLogging:
user_api_key_dict = UserAPIKeyAuth(
parent_otel_span=parent_otel_span,
token=_hash_token_if_needed(token=api_key),
token=_hash_token_if_needed(token=api_key or ""),
)
request_data = await request.json()
try:
request_data = await request.json()
except json.JSONDecodeError:
# For GET requests or requests without a JSON body
request_data = {}
await self._run_post_call_failure_hook_custom_loggers(
original_exception=original_exception,
request_data=request_data,