Intercept HTTP request status code before download
===

My Problem is pretty simple. I have a server-side script that runs which generates an image and streams it back to the client. The script can fail given certain conditions (stress/load on server). What I need to do is capture the status code of the request on the client and if the status code is OK (200) then proceed download and if it's 5XX display an error dialogue to the user.

Currently, I'm using window.location = "path"; on the client to send the request to the server. The problem with this is how can I grab the status code. Are there any lower level functions which can perform this functionality?

I've read into using just a HEAD request to capture the HTTP headers however there are problems with this and it's not my ideal solution.