(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,6 +6497,7 @@ async def health_services_endpoint(
Used by the UI to let user check if slack alerting is working as expected. Used by the UI to let user check if slack alerting is working as expected.
""" """
try:
global general_settings, proxy_logging_obj global general_settings, proxy_logging_obj
if service is None: if service is None:
@ -6513,11 +6514,31 @@ async def health_services_endpoint(
) )
if "slack" in general_settings.get("alerting", []): if "slack" in general_settings.get("alerting", []):
await proxy_logging_obj.alerting_handler(message="This is a test", level="Low") await proxy_logging_obj.alerting_handler(
message="This is a test", level="Low"
)
else: else:
raise HTTPException( raise HTTPException(
status_code=422, status_code=422,
detail={"error": "No slack connection setup. Unable to test this."}, 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,
) )