utils: simplify subclassing APIError (#86422)

By making err, http_status and log_error class variables with their
default values.
This commit is contained in:
Benjamin Dauvergne 2024-02-01 18:43:46 +01:00
parent 3c30a76f3e
commit 45f6ee9e8d
1 changed files with 7 additions and 3 deletions

View File

@ -28,10 +28,14 @@ CALLBACK_NAME = getattr(settings, 'JSONRESPONSE_CALLBACK_NAME', 'callback')
class APIError(RuntimeError):
'''Exception to raise when there is a remote application or business logic error.'''
err = 1
http_status = 200
log_error = False
def __init__(self, *args, **kwargs):
self.err = kwargs.pop('err', 1)
self.log_error = kwargs.pop('log_error', False)
self.http_status = kwargs.pop('http_status', 200)
self.err = kwargs.pop('err', self.err)
self.log_error = kwargs.pop('log_error', self.log_error)
self.http_status = kwargs.pop('http_status', self.http_status)
self.__dict__.update(kwargs)
super().__init__(*args)