1+ from django .utils .encoding import force_str
12from rest_framework import status
23from rest_framework .exceptions import APIException as _DRFAPIException
34from django .utils .translation import gettext_lazy as _
67from kirovy .objects import ui_objects
78
89
9- class KirovyValidationError (_DRFAPIException ):
10- """A custom exception that easily converts to the standard ``ErrorResponseData``
11-
12- See: :class:`kirovy.objects.ui_objects.ErrorResponseData`
13-
14- This exception is meant to be used within serializers or views.
15- """
16-
17- status_code = status .HTTP_400_BAD_REQUEST
18- default_detail = _ ("Invalid input." )
19- default_code = "invalid"
10+ class KirovyAPIException (_DRFAPIException ):
11+ status_code : _t .ClassVar [int ] = status .HTTP_500_INTERNAL_SERVER_ERROR
2012 additional : _t .DictStrAny | None = None
2113 code : str | None
2214 """attr: Some kind of string that the UI will recognize. e.g. ``file-too-large``.
@@ -41,3 +33,29 @@ def __init__(self, detail: str | None = None, code: str | None = None, additiona
4133
4234 def as_error_response_data (self ) -> ui_objects .ErrorResponseData :
4335 return ui_objects .ErrorResponseData (message = self .detail , code = self .code , additional = self .additional )
36+
37+
38+ class KirovyValidationError (KirovyAPIException ):
39+ """A custom exception that easily converts to the standard ``ErrorResponseData``
40+
41+ See: :class:`kirovy.objects.ui_objects.ErrorResponseData`
42+
43+ This exception is meant to be used within serializers or views.
44+ """
45+
46+ status_code = status .HTTP_400_BAD_REQUEST
47+ default_detail = _ ("Invalid input." )
48+ default_code = "invalid"
49+
50+
51+ class KirovyMethodNotAllowed (KirovyAPIException ):
52+ status_code = status .HTTP_405_METHOD_NOT_ALLOWED
53+ default_detail = _ ('Method "{method}" not allowed.' )
54+ default_code = "method_not_allowed"
55+
56+ def __init__ (
57+ self , method , detail : str | None = None , code : str | None = None , additional : _t .DictStrAny | None = None
58+ ):
59+ if detail is None :
60+ detail = force_str (self .default_detail ).format (method = method )
61+ super ().__init__ (detail , code , additional )
0 commit comments