From e716b330de4a11915116c39b116d2f2271409a09 Mon Sep 17 00:00:00 2001 From: Jarrett Keifer Date: Sat, 12 Aug 2023 19:33:42 -0700 Subject: [PATCH] better error when offset doesn't match expected --- src/drf_chunked_upload/views.py | 9 ++++++--- tests/test_uploads.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/drf_chunked_upload/views.py b/src/drf_chunked_upload/views.py index 5b9c177..d3bc90f 100644 --- a/src/drf_chunked_upload/views.py +++ b/src/drf_chunked_upload/views.py @@ -187,9 +187,12 @@ def _put_chunk(self, request, pk=None, whole=False, *args, **kwargs): pk=upload_id) self.is_valid_chunked_upload(chunked_upload) if chunked_upload.offset != start: - raise ChunkedUploadError(status=status.HTTP_400_BAD_REQUEST, - detail='Offsets do not match', - offset=chunked_upload.offset) + raise ChunkedUploadError( + status=status.HTTP_400_BAD_REQUEST, + detail='Offsets do not match', + expected_offset=chunked_upload.offset, + provided_offset=start, + ) chunked_upload.append_chunk(chunk, chunk_size=chunk_size) else: diff --git a/tests/test_uploads.py b/tests/test_uploads.py index 420bf64..a7b088f 100644 --- a/tests/test_uploads.py +++ b/tests/test_uploads.py @@ -189,7 +189,8 @@ def test_chunked_upload_wrong_order(view, user1): print(response.data) assert response.status_code == status.HTTP_400_BAD_REQUEST assert response.data['detail'] == 'Offsets do not match' - assert response.data['offset'] == 10 + assert response.data['expected_offset'] == 10 + assert response.data['provided_offset'] == 20 @pytest.mark.django_db