Fetch 200 but response body empty

Sometimes when making a request, the request body is working fine and sometimes the body is empty. I know my api is fine because i tested it a lot with postman I found that if I put req.clone and await clone.text() the response body always returns even though I am not doing anything with the clone I just added that code This is nextjs api server request any ideas??
const res = await fetch(forwardUrl, {
...req,
headers: forwardHeaders,
method: req.method,
// body: req.method !== "GET" ? body : null,
body: body ? JSON.stringify(body) : null,
cache: "no-store",
// @ts-ignore
// duplex: "half",
});

// console.log("Response Status", res.status);
// console.log("Response Type", res.type);
// console.log("Response Content Length", res.headers.get("Content-Length"));
// console.log("Response Content Type", res.headers.get("Content-Type"));

// // Clone the response for inspection or logging
// const clone = res.clone();

// // Use the clone to read the body for logging or other processing
// await clone.text(); // or clone.json() if expecting JSON

return new Response(res.body, {
status: res.status,
});
const res = await fetch(forwardUrl, {
...req,
headers: forwardHeaders,
method: req.method,
// body: req.method !== "GET" ? body : null,
body: body ? JSON.stringify(body) : null,
cache: "no-store",
// @ts-ignore
// duplex: "half",
});

// console.log("Response Status", res.status);
// console.log("Response Type", res.type);
// console.log("Response Content Length", res.headers.get("Content-Length"));
// console.log("Response Content Type", res.headers.get("Content-Type"));

// // Clone the response for inspection or logging
// const clone = res.clone();

// // Use the clone to read the body for logging or other processing
// await clone.text(); // or clone.json() if expecting JSON

return new Response(res.body, {
status: res.status,
});
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server