fix - custom APIExceptions for quota stats

This commit is contained in:
2025-11-18 09:11:35 +03:30
parent d8f6eaf243
commit 4e5319b625
3 changed files with 67 additions and 11 deletions

View File

@@ -2,6 +2,44 @@ from rest_framework import status
from rest_framework.exceptions import APIException
class QuotaException(APIException):
""" if quota is not available """
status_code = status.HTTP_400_BAD_REQUEST
default_detail = "خطا در اطلاعات سهمیه" # noqa
default_code = 'error'
def __init__(self, message=None, status_code=None, code=None):
if status_code is not None:
self.status_code = status_code
detail = {
"message": message,
"status_code": status_code
}
super().__init__(detail)
class DistributionException(APIException):
""" if distribution is not available """
status_code = status.HTTP_400_BAD_REQUEST
default_detail = "خطا در اطلاعات توزیع." # noqa
default_code = 'error'
def __init__(self, message=None, status_code=None, code=None):
if status_code is not None:
self.status_code = status_code
detail = {
"message": message,
"status_code": status_code
}
super().__init__(detail)
class QuotaWeightException(APIException):
""" if quota distributions weight is more """