Enhanced time synchronization for drf views.
better exceptions
2 files changed, +8 -5
+7-5plusrequest/exceptions.py
| @@ -5,7 +5,8 @@ from rest_framework import exceptions | ||
| 5 | 5 | class InvalidServerDatetimeField(exceptions.APIException): |
| 6 | 6 | def __init__(self, field_name: str, val: Any, code: str | int): |
| 7 | 7 | super().__init__( |
| 8 | - f"{field_name} is not a valid datetime. {val} is a {type(val)}", str(code) | |
| 8 | + f"InvalidServerDatetimeField: {field_name} is not a valid datetime. {val} is a {type(val)}", | |
| 9 | + str(code), | |
| 9 | 10 | ) |
| 10 | 11 | |
| 11 | 12 | |
| @@ -13,7 +14,7 @@ class InvalidClientDatetimeField(exceptions.APIException): | ||
| 13 | 14 | def __init__(self, field_name: str, val: str, fmt: str, code: str | int): |
| 14 | 15 | code = str(code) |
| 15 | 16 | super().__init__( |
| 16 | - f"{field_name} header {val} val is unable to be parsed with {fmt}", | |
| 17 | + f"InvalidClientDatetimeField: {field_name} header {val} val is unable to be parsed with {fmt}", | |
| 17 | 18 | code, |
| 18 | 19 | ) |
| 19 | 20 | |
| @@ -23,9 +24,10 @@ class NoUpdate(exceptions.APIException): | ||
| 23 | 24 | code = str(code) |
| 24 | 25 | if request_method in ["POST", "PUT"]: |
| 25 | 26 | super().__init__( |
| 26 | - "Client has submitted older data than the server. Skipping update", code | |
| 27 | + "NoUpdate: Client has submitted older data than the server. Skipping update", | |
| 28 | + code, | |
| 27 | 29 | ) |
| 28 | 30 | elif request_method == "GET": |
| 29 | - super().__init__("Client is already up to date", code) | |
| 31 | + super().__init__("NoUpdate: Client is already up to date", code) | |
| 30 | 32 | else: |
| 31 | - super().__init__("No update", code) | |
| 33 | + super().__init__("NoUpdate", code) |
+1-0plusrequest/request.py
| @@ -23,3 +23,4 @@ class PlusRequest(Request, HttpRequest): | ||
| 23 | 23 | ... |
| 24 | 24 | return Response(data) |
| 25 | 25 | ```""" |
| 26 | + return TimestampOp(self) |