Why do I get "Fetch failed loading" when it actually worked? Why do I get "Fetch failed loading" when it actually worked? google-chrome google-chrome

Why do I get "Fetch failed loading" when it actually worked?


I had the same behaviour that you were seeing. My server responded to the POST request with a 204 (Empty Response) and an empty (Content-Length=0) response. I tried changing that to just respond with a "ok" message instead (edit: actually just returning the created object now) and the fetch error log disappeared.

It seems to me that fetch (at least in Chrome) erroneously logs "Fetch Failed" when the response body is empty, even if the request was successful.


This happens because you don't read the empty response body. I noticed this, because Django triggers a broken pipe error on the server side. To fix this, just read the empty body out.

async function fetchSomething() {    const response = await fetch(url, {        method: 'POST'    })    await response.text()    return response.ok}