Skip to content

Commit

Permalink
better error when offset doesn't match expected
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeifer committed Aug 13, 2023
1 parent ed96cf3 commit e716b33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/drf_chunked_upload/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e716b33

Please sign in to comment.