(feat) improve error for testing slack

This commit is contained in:
ishaan-jaff 2024-03-02 16:46:20 -08:00
parent 0b85061086
commit ebaf2eef1f

View file

@ -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,
)