I use the REST service to create a CSV file that I want to prompt the user to download. An example service is shown below:
https://localhost:8444/websvc/exportCSV?viewId=93282392
To request the user to download the file, I use this code:
window.location.href = exportUrl , where exportUrl will be a URL similar to the one above.
This works fine if there are no errors on the server while running the service. A prompt appears to download the file, the page will not refresh, and everything will be fine.
However, if the error , I get a nasty 500 HTTP status page, which is not suitable for users. What I would like to do is to catch any error on the final page and cause a more friendly error without leaving the current page. I tried:
try { window.location.href = exportUrl; } catch (e) { alert(e); }
But this does not change the behavior at all. Anyone have any ideas on how to handle this?
Many thanks.
javascript window.location try-catch error-handling
Matt powell
source share