Detecting download error in FF


  • ♿ (Parody)

    I've got some links from which users can download documents that we generate. They use the download attribute so the browser doesn't try to display them. But sometimes there's an error (usually because our PDF generation component has fallen over). The server returns a standard 500.

    On chromium type browsers, the browser tells the user that there was a server error. Basically, instead of allowing you to click the "button" with the file name (or view in folder, etc) it says something like, "Server Error." Likewise, if you look in the actual download manager's history.

    Firefox, OTOH, pretends (AFAICT) like nothing ever happened. But I'd really like to let the user know that there was an error somehow, but I can't figure out how to make that happen.



  • I'm used to just send the file with a Content-Disposition: attachment header. Never knew there is a download attribute.

    When using Content-Disposition with a target blank, a new tab is opened with a error when the download fails in Firefox if I'm not mistaken.


  • ♿ (Parody)

    @littletijn we were doing that originally (and still do). But when you get an error the browser gives an error about bad JSON. Which, I dunno...maybe is Angular doing stuff?

    Adding download (which is was introduced in html5) at least prevents that, which is what I'm supposed to be fixing. It's like the FF devs never considered the possibility of getting a 500 when trying to download.



  • @boomzilla said in Detecting download error in FF:

    devs never considered the possibility

    :surprised-pikachu:



  • @boomzilla Is it possible that the download in Angular is done in Javascript instead of a plain-old Hyperlink? (That there is a click handler on the link processed by Angular?) That might explain the JSON error.

    I have tried to make a download link with a download attribute and a target attribute. Even with the target="_blank" attribute Firefox will show nothing at all. Even in the network tab of the developer tools.

    5fb0c7c6-dc73-4596-b8c7-b81ffa458b29-afbeelding.png

    (Pardon me for the Dutchy words in the picture)

    In Microsoft Edge Chromium Edition (I know) it works just fine.

    Only advice I can give is using Content-Disposition: attachment with a target="_blank" instead of a download attribute. Unfortunately, the server needs to send it with the download. Static files will not have it by default.

    EDIT: It is also possible to download the file first with Javascript and return the blob as a download. Although it is not that great. Problem is that the browser will show a download message after the whole file has been downloaded by Javascript.


  • ♿ (Parody)

    @littletijn said in Detecting download error in FF:

    Is it possible that the download in Angular is done in Javascript instead of a plain-old Hyperlink? (That there is a click handler on the link processed by Angular?) That might explain the JSON error.

    Hmm...I'll take a closer look on Monday. I assumed it didn't because we have a service that intercepts errors and shows a message to users and it doesn't see anything.

    EDIT: It is also possible to download the file first with Javascript and return the blob as a download. Although it is not that great. Problem is that the browser will show a download message after the whole file has been downloaded by Javascript

    Yeah, this seems to be the common solution that I've found out on stackoverflow, etc. I do know that some of these files can get pretty big (like...2+GB) so I'd like to avoid that if possible. The positive for this is that I can display a normal spinner (like we do for other requests) and the existing error handling would work just fine.


  • ♿ (Parody)

    Here's what I ended up doing:

    On the server side:

    Set up a cache in the user's session where I track the state of the document generation, started, complete or error.

    On the front end:

    Added an onclick handler that uses setTimeout to check on the status every half a second. Also, throws up a spinner so the user knows stuff is happening. When complete, just dismiss the spinner and life goes on. When there's an error, throw up the generic "An error occurred" stuff.


Log in to reply