mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-20 16:01:34 +02:00
Include the current ETag in the 412 response
This commit is contained in:
@@ -61,7 +61,13 @@ class ETagMixin:
|
|||||||
if provided := self._get_if_match(request):
|
if provided := self._get_if_match(request):
|
||||||
current_etag = self._get_etag(instance)
|
current_etag = self._get_etag(instance)
|
||||||
if current_etag and current_etag not in provided:
|
if current_etag and current_etag not in provided:
|
||||||
raise PreconditionFailed()
|
raise PreconditionFailed(etag=current_etag)
|
||||||
|
|
||||||
|
def handle_exception(self, exc):
|
||||||
|
response = super().handle_exception(exc)
|
||||||
|
if isinstance(exc, PreconditionFailed) and exc.etag:
|
||||||
|
response['ETag'] = exc.etag
|
||||||
|
return response
|
||||||
|
|
||||||
def retrieve(self, request, *args, **kwargs):
|
def retrieve(self, request, *args, **kwargs):
|
||||||
instance = self.get_object()
|
instance = self.get_object()
|
||||||
|
|||||||
@@ -44,11 +44,16 @@ class PermissionsViolation(Exception):
|
|||||||
class PreconditionFailed(APIException):
|
class PreconditionFailed(APIException):
|
||||||
"""
|
"""
|
||||||
Raised when an If-Match precondition is not satisfied (HTTP 412).
|
Raised when an If-Match precondition is not satisfied (HTTP 412).
|
||||||
|
Optionally carries the current ETag so it can be included in the response.
|
||||||
"""
|
"""
|
||||||
status_code = status.HTTP_412_PRECONDITION_FAILED
|
status_code = status.HTTP_412_PRECONDITION_FAILED
|
||||||
default_detail = 'Precondition failed.'
|
default_detail = 'Precondition failed.'
|
||||||
default_code = 'precondition_failed'
|
default_code = 'precondition_failed'
|
||||||
|
|
||||||
|
def __init__(self, detail=None, code=None, etag=None):
|
||||||
|
super().__init__(detail=detail, code=code)
|
||||||
|
self.etag = etag
|
||||||
|
|
||||||
|
|
||||||
class RQWorkerNotRunningException(APIException):
|
class RQWorkerNotRunningException(APIException):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user