Browse Source

fix(discord): Log and warn rather than raise error (#62341)

Closes https://github.com/getsentry/sentry/issues/62316

We don't need to raise an error here, just let the user know that they
must be logged in.

<img width="830" alt="Screenshot 2024-01-02 at 12 23 20 PM"
src="https://github.com/getsentry/sentry/assets/22582037/2fcaa7df-0808-479d-a4bf-0775c146ae35">
Julia Hoge 1 year ago
parent
commit
7f8126847d

+ 9 - 3
src/sentry/integrations/discord/webhooks/command.py

@@ -1,7 +1,5 @@
-from rest_framework import status
 from rest_framework.response import Response
 
-from sentry.integrations.discord.requests.base import DiscordRequestError
 from sentry.integrations.discord.views.link_identity import build_linking_url
 from sentry.integrations.discord.views.unlink_identity import build_unlinking_url
 from sentry.integrations.discord.webhooks.handler import DiscordInteractionHandler
@@ -10,6 +8,7 @@ from ..utils import logger
 
 LINK_USER_MESSAGE = "[Click here]({url}) to link your Discord account to your Sentry account."
 ALREADY_LINKED_MESSAGE = "You are already linked to the Sentry account with email: `{email}`."
+MISSING_DATA_MESSAGE = "You must be logged into your Sentry account for the link action to work."
 UNLINK_USER_MESSAGE = "[Click here]({url}) to unlink your Discord account from your Sentry Account."
 NOT_LINKED_MESSAGE = (
     "Your Discord account is not linked to a Sentry account. Use `/link` to link your accounts."
@@ -59,7 +58,14 @@ class DiscordCommandHandler(DiscordInteractionHandler):
             )
 
         if not self.request.integration or not self.request.user_id:
-            raise DiscordRequestError(status=status.HTTP_400_BAD_REQUEST)
+            logger.warning(
+                "discord.interaction.command.missing.integration",
+                extra={
+                    "hasIntegration": bool(self.request.integration),
+                    "hasUserId": self.request.user_id,
+                },
+            )
+            return self.send_message(MISSING_DATA_MESSAGE)
 
         link_url = build_linking_url(
             integration=self.request.integration,

+ 2 - 2
tests/sentry/integrations/discord/webhooks/test_command.py

@@ -44,7 +44,7 @@ class DiscordCommandInteractionTest(APITestCase):
                 HTTP_X_SIGNATURE_ED25519="signature",
                 HTTP_X_SIGNATURE_TIMESTAMP="timestamp",
             )
-        assert resp.status_code == 400
+        assert resp.status_code == 200
 
     def test_link_no_user_id(self):
         guild_id = "guild-id"
@@ -69,7 +69,7 @@ class DiscordCommandInteractionTest(APITestCase):
                 HTTP_X_SIGNATURE_ED25519="signature",
                 HTTP_X_SIGNATURE_TIMESTAMP="timestamp",
             )
-        assert resp.status_code == 400
+        assert resp.status_code == 200
 
     def test_link_guild(self):
         guild_id = "guild-id"