Hi there,
I am having trouble when returning 204 http status code from Next.js (latest today) from a api route (METHOD: DELETE)
To Reproduce
- Inside API route do a DELETE handler
- Return status (HTTP Status Code) 204
export async function DELETE(request: NextRequest, { params }: ResponseUtils['PARAMS']) {
const service = serviceImpl();
const { id } = params;
try {
IdSchema.parse({ id });
} catch (error) {
return defaultServerErrorHandler(error);
}
try {
// The request is completed successfully, and the response is a 204 No Content status code.
const { status } = await service.delete.byId(id);
// The response body is empty and the status code is 204.
// But when trying to return the response, it throws the following error:
// {"message":"Response constructor: Invalid response status code 204"}
// I tried all the following options, but none of them worked:
return NextResponse.json({}, { status });
// return NextResponse.json(null, { status });
// return NextResponse.json('', { status });
// return NextResponse.json(undefined, { status }); // This is actually invalid (Value is not JSON serializable)
} catch (error) {
return defaultServerErrorHandler(error);
}
}
Do you know some workaround about this issue or it is just me?