Fixes: 1) Handle generic Exception in current method of viewsets to prevent 500 errors;

Extra: 1) Add fallback error response with status 400 for unexpected exceptions.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-10-02 13:19:21 +03:00
parent 4bce9224fc
commit 447f70d17a

View file

@ -840,6 +840,8 @@ class OrderViewSet(EvibesViewSet):
except Order.DoesNotExist: except Order.DoesNotExist:
name = "Order" name = "Order"
return Response(status=status.HTTP_404_NOT_FOUND, data={"detail": _(f"{name} does not exist: {uuid}")}) return Response(status=status.HTTP_404_NOT_FOUND, data={"detail": _(f"{name} does not exist: {uuid}")})
except Exception as e:
return Response(status=status.HTTP_400_BAD_REQUEST, data={"detail": str(e)})
@action(detail=False, methods=["post"], url_path="buy_unregistered") @action(detail=False, methods=["post"], url_path="buy_unregistered")
@method_decorator(ratelimit(key="ip", rate="10/h" if not settings.DEBUG else "888/h")) @method_decorator(ratelimit(key="ip", rate="10/h" if not settings.DEBUG else "888/h"))