In Firefox' JavaScript engine I do a (deprecated) synchronous XMLHttpRequest like this:
var request = new XMLHttpRequest();
request.open('GET', 'http://localhost:8780/BoilerData/invention.html', false);
request.send();
if (request.status === 200) {
...
} else {
...
}
Problem is when the server myserver.com is not running I get in the browser console a NS ERROR FAILURE error and the else part is not executed.
However I would like to react to this error in JavaScript. How can I catch this error and react to it (e.g. with using another server) while still doing a a synchronous XMLHttpRequest.
Update
Here more details to the error message. In the console of my browser (Firefox 78.4.1esr) I see the following:

XMLHttpRequestinstead ofawait fetch()is so popular, and even less sure why forcing asynchronous things to be synchronous and blocking the UI is such a trend these days... Synchronous requests were never a thing. It's not really deprecated because it's never been "precated"(?) in the first place.