Skip to content

Commit 34ae14f

Browse files
committed
Solving 500 error when deleting item
1 parent 28cb881 commit 34ae14f

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

backend/market/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def destroy(self, request, *args, **kwargs):
332332
obj = get_object_or_404(queryset, **filter)
333333
self.check_object_permissions(self.request, obj)
334334
self.perform_destroy(obj)
335-
return Response({"deleted": True}, status=status.HTTP_204_NO_CONTENT)
335+
return Response(status=status.HTTP_204_NO_CONTENT)
336336

337337
def list(self, request, *args, **kwargs):
338338
if not Listing.objects.filter(pk=int(self.kwargs["listing_id"])).exists():

frontend/components/listings/detail/ListingDetail.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,8 @@ export const ListingDetail = ({
381381
if (isDeleting) return;
382382
setIsDeleting(true);
383383
try {
384-
const res = await deleteListing(listingState.id);
385-
console.log(res);
386-
window.location.href = "/";
384+
await deleteListing(listingState.id);
385+
window.location.href = "/items";
387386
} catch (err) {
388387
console.log(err);
389388
setIsDeleting(false);

frontend/lib/actions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ async function serverFetch<T>(endpoint: string, options: RequestInit = {}): Prom
9999
throw new APIError(errorMessage, response.status);
100100
}
101101

102+
if (response.status === 204 || response.status === 205) {
103+
return undefined as T;
104+
}
102105
return response.json();
103106
}
104107

@@ -313,8 +316,8 @@ export async function updateListing(
313316
});
314317
}
315318

316-
export async function deleteListing(listingId: number): Promise<Listing> {
317-
return await serverFetch<Listing>(`/market/listings/${listingId}/`, {
319+
export async function deleteListing(listingId: number): Promise<void> {
320+
await serverFetch<void>(`/market/listings/${listingId}/`, {
318321
method: "DELETE",
319322
});
320323
}

0 commit comments

Comments
 (0)