diff --git a/store/views.py b/store/views.py index f26d653..a1cde80 100644 --- a/store/views.py +++ b/store/views.py @@ -14,7 +14,7 @@ from rest_framework.response import Response from external_api.cdek import CDEKClient, CDEKWebhookTypes, CDEK_STATUS_TO_ORDER_STATUS from external_api.poizon import PoizonClient -from utils.exceptions import CRMException +from utils.exceptions import CRMException, Forbidden from store.filters import GiftFilter, ChecklistFilter from store.models import Checklist, Category, PaymentMethod, Promocode, Gift from core.models import GlobalSettings @@ -92,7 +92,7 @@ class ChecklistAPI(viewsets.ModelViewSet): # Non-managers can cancel orders only in certain statuses if (not getattr(self.request.user, 'is_manager', False) and obj.status not in Checklist.Status.CANCELLABLE_ORDER_STATUSES): - raise CRMException("Can't delete the order") + raise Forbidden("Can't delete the order") obj.cancel() diff --git a/utils/exceptions.py b/utils/exceptions.py index 13ccf4e..ff3b1d2 100644 --- a/utils/exceptions.py +++ b/utils/exceptions.py @@ -12,4 +12,7 @@ class CRMException(APIException): self.detail = {'error': detail} +class Forbidden(CRMException): + status_code = status.HTTP_403_FORBIDDEN + # TODO: exceptions with a same template: ok / error_code / error_message