[File download] Error handling

[File download] Error handling

Hello,

I want to download a file from my server.
The file is generated on the fly with this request:
location.href = '/export/generate?start=' + start + "&end=" + end;

It works fine.
It prints a popup to either save the file or open it.

My problem is how to handle errors, when for example the date are not well formatted.
The server returns a 400 HTTP error, and I would like to catch this error in javascript and print a message in a web page.
Something like the error handler of the ajax function.

Any idea?

Thanks
Nicolas