Browse Source

fix(api): Correct plain/text version of catchall help message (#44206)

Evan Purkhiser 2 years ago
parent
commit
94bbc3264d

+ 4 - 3
src/sentry/api/endpoints/catchall.py

@@ -23,9 +23,10 @@ class CatchallEndpoint(Endpoint):
             if request.META.get("CONTENT_TYPE", "").startswith("application/json"):
                 return JsonResponse(data={"info": f"{help} {suggestion}"}, status=404)
 
-            # Produce error message with a pointer to the trailing slash
-            arrow = f"{' ' * len(suggestion)}^"
-            message = f"{help}\n\n{suggestion}{request.path}/\n{arrow}\n"
+            # Produce error message with a pointer to the trailing slash in plain text
+            arrow_offset = len(suggestion) - 1
+            arrow = f"{' ' * arrow_offset}^"
+            message = f"{help}\n\n{suggestion}\n{arrow}\n"
 
             return HttpResponse(message, status=404, content_type="text/plain")
 

+ 6 - 1
tests/sentry/api/endpoints/test_catchall.py

@@ -20,7 +20,12 @@ class CatchallTestCase(APITestCase):
         response = self.client.get("/api/0/bad_url")
         assert_status_code(response, status.HTTP_404_NOT_FOUND)
 
-        assert b"Route not found, did you forget a trailing slash?" in response.content
+        assert (
+            b"Route not found, did you forget a trailing slash?\n\n"
+            + b"try: /api/0/bad_url/\n"
+            + b"                   ^\n"
+            in response.content
+        )
 
     def test_trailing_slash_help_json(self):
         response = self.client.get("/api/0/bad_url", content_type="application/json")