Просмотр исходного кода

feat(discord): Improve missing channel error messages (#56960)

Closes https://github.com/getsentry/sentry/issues/55203
Closes https://github.com/getsentry/sentry/issues/54209
Julia Hoge 1 год назад
Родитель
Сommit
b99b3eb9d1
1 измененных файлов с 41 добавлено и 5 удалено
  1. 41 5
      src/sentry/integrations/discord/utils/channel.py

+ 41 - 5
src/sentry/integrations/discord/utils/channel.py

@@ -20,11 +20,47 @@ def validate_channel_id(channel_id: str, guild_id: str, integration_id: int | No
     try:
         result = client.get_channel(channel_id)
     except ApiError as e:
-        if e.code in (400, 403, 404):
-            logger.info("rule.discord.channel_info_failed", extra={"error": str(e)})
-            raise ValidationError(NO_CHANNEL_MESSAGE)
-        logger.error("rule.discord.channel_info_failed", extra={"error": str(e)})
-        raise IntegrationError("Could not retrieve Discord channel information.")
+        if e.code == 400:
+            logger.info(
+                "rule.discord.channel_info_failed",
+                extra={
+                    "channel_id": channel_id,
+                    "reason": "channel ID missing or malformed",
+                    "code": e.code,
+                },
+            )
+            raise ValidationError("Discord channel id is missing or not formatted correctly")
+        elif e.code == 403:
+            logger.info(
+                "rule.discord.channel_info_failed",
+                extra={
+                    "channel_id": channel_id,
+                    "reason": "channel access not allowed",
+                    "code": e.code,
+                },
+            )
+            raise ValidationError("Discord channel exists but access is not allowed")
+        elif e.code == 404:
+            logger.info(
+                "rule.discord.channel_info_failed",
+                extra={
+                    "channel_id": channel_id,
+                    "reason": "channel not found",
+                    "code": e.code,
+                },
+            )
+            raise ValidationError("Discord channel can not be found.")
+        else:
+            logger.info(
+                "rule.discord.channel_integration_failed",
+                extra={
+                    "guild_id": guild_id,
+                    "channel_id": channel_id,
+                    "reason": "channel does not belong to indicated guild (server)",
+                    "code": e.code,
+                },
+            )
+            raise IntegrationError("Discord channel does not belong to the server indicated.")
 
     if not isinstance(result, dict):
         raise IntegrationError("Bad response from Discord channel lookup.")