From ebaf2eef1f3d4cdbb3cc6cf7187b940056762671 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 2 Mar 2024 16:46:20 -0800 Subject: [PATCH] (feat) improve error for testing slack --- litellm/proxy/proxy_server.py | 57 ++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index ffae102a0..b6796a81b 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -6497,27 +6497,48 @@ async def health_services_endpoint( Used by the UI to let user check if slack alerting is working as expected. """ - global general_settings, proxy_logging_obj + try: + global general_settings, proxy_logging_obj - if service is None: - raise HTTPException( - status_code=400, detail={"error": "Service must be specified."} - ) + if service is None: + raise HTTPException( + status_code=400, detail={"error": "Service must be specified."} + ) - if service not in ["slack_budget_alerts"]: - raise HTTPException( - status_code=400, - detail={ - "error": f"Service must be in list. Service={service}. List={['slack_budget_alerts']}" - }, - ) + if service not in ["slack_budget_alerts"]: + raise HTTPException( + status_code=400, + detail={ + "error": f"Service must be in list. Service={service}. List={['slack_budget_alerts']}" + }, + ) - if "slack" in general_settings.get("alerting", []): - await proxy_logging_obj.alerting_handler(message="This is a test", level="Low") - else: - raise HTTPException( - status_code=422, - detail={"error": "No slack connection setup. Unable to test this."}, + if "slack" in general_settings.get("alerting", []): + await proxy_logging_obj.alerting_handler( + message="This is a test", level="Low" + ) + else: + raise HTTPException( + status_code=422, + detail={ + "error": '"slack" not in proxy config: general_settings. Unable to test this.' + }, + ) + except Exception as e: + if isinstance(e, HTTPException): + raise ProxyException( + message=getattr(e, "detail", f"Authentication Error({str(e)})"), + type="auth_error", + param=getattr(e, "param", "None"), + code=getattr(e, "status_code", status.HTTP_401_UNAUTHORIZED), + ) + elif isinstance(e, ProxyException): + raise e + raise ProxyException( + message="Authentication Error, " + str(e), + type="auth_error", + param=getattr(e, "param", "None"), + code=status.HTTP_401_UNAUTHORIZED, )