|
@@ -1,7 +1,6 @@
|
|
-from django.http import HttpResponse
|
|
|
|
|
|
+from django.http import HttpResponse, JsonResponse
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from rest_framework.request import Request
|
|
from rest_framework.request import Request
|
|
-from rest_framework.response import Response
|
|
|
|
|
|
|
|
from sentry.api.base import Endpoint, pending_silo_endpoint
|
|
from sentry.api.base import Endpoint, pending_silo_endpoint
|
|
|
|
|
|
@@ -11,5 +10,23 @@ class CatchallEndpoint(Endpoint):
|
|
permission_classes = ()
|
|
permission_classes = ()
|
|
|
|
|
|
@csrf_exempt
|
|
@csrf_exempt
|
|
- def dispatch(self, request: Request, *args, **kwargs) -> Response:
|
|
|
|
|
|
+ def dispatch(self, request: Request, *args, **kwargs) -> HttpResponse:
|
|
|
|
+ """
|
|
|
|
+ This endpoint handles routes that did not match
|
|
|
|
+ """
|
|
|
|
+ # Let the user know they may have forgotten a trailing slash
|
|
|
|
+ if not request.path.endswith("/"):
|
|
|
|
+ help = "Route not found, did you forget a trailing slash?"
|
|
|
|
+ suggestion = f"try: {request.path}/"
|
|
|
|
+
|
|
|
|
+ # Don't break JSON parsers
|
|
|
|
+ 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"
|
|
|
|
+
|
|
|
|
+ return HttpResponse(message, status=404, content_type="text/plain")
|
|
|
|
+
|
|
return HttpResponse(status=404)
|
|
return HttpResponse(status=404)
|