Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome fails to download response body if HTTP status is an error code

I have a Node.js Express web server that returns an HTTP response JSON payload along with an error status (4xx or 5xx) when something goes wrong.

res.status(500).json({ error: 'message' });

From the Chrome browser developer console's Timing section, I can see a lot of time (up to 5 minutes) spent in the "Content Download" segment and ultimately I am getting "Failed to load response data" in the Response section after download fails.

Chrome developer console timing output

Other browsers like Firefox and Opera are able to successfully download the JSON payload successfully and display them in their respective developer consoles.

If I send back the HTTP status as 200, Chrome has no trouble downloading the payload.

Also, if I do not set the Cache-Control HTTP headers to "no-store, no cache...", Chrome is able to successfully download the payload with 4xx/5xx status. However, I would like to set this header as a good practice against cache misuse.

HTTP Response Headers in the success and failure case

Is there something specific I need to do for Chrome?

Thank you!

like image 255
Gautam Satish Avatar asked Dec 07 '17 10:12

Gautam Satish


People also ask

Does the browser automatically download the response as a file?

Content-Length: 134772 Content-Type: application/pcap Now I was told that if the header will be like so, the browser will automatically start downloading the response as a file. It doesn't. So I've read very little about Blob, and FileSaver, but I feel like there must be an easier way to download files that are being created dynamically.

What do the HTTP response status codes mean?

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes: Skip to main content Skip to search Skip to select language Open main menu

Why does chrome download failed network error?

And no matter how many times you try downloading your files, the process keeps failing. Although the error message suggests that the issue is with "a network," this is not always the case. So, let's check out what causes the "Chrome download failed network error" and explore all possible solutions. 1. Check Your Internet Speed and Connection

Why can't I download a file on Chrome?

The Windows Attachment Manager helps protect your computer from unsafe files that you download or receive via email. If it considers a file unsafe, it blocks you from downloading it. So, this Windows tool might be the reason you're encountering the "failed download error" on Chrome.


1 Answers

I just had a similar problem. For the request I used the fetch API and in case of an error I did not read the stream of the response body.

Neither the content of the response body was displayed in the devtools nor was the request included in the HAR export.

After debugging this in the console I noticed that the content is displayed in the response or preview tab as soon as I was reading the stream. (e.g.: await response.text())

Strangely enough the behavior changes as you described when the corresponding cache headers are not set.

like image 79
Ivaldi Avatar answered Sep 20 '22 19:09

Ivaldi