Background: I come from the Python world where a try:
/ except:
completely handles the exception, i.e. I can control what is being output when an exception is caught.
I am making an AJAX call to an API which may not be available:
function updateAPI() {
getAPI()
.done(function (r) {
console.log('got API response: ' + JSON.stringify(r));
updateFromAPI(r);
})
.fail(function (r) {
console.log('failed to get API response: ' + r);
}
);
}
function getAPI() {
return $.ajax({
type: 'GET',
url: 'http://127.0.0.1:8081/api'
});
}
I was expecting to get one of my two messages sent to the console, and just that. The console, however, also shows the actual error, logged by JS:
Failed to load resource: net::ERR_CONNECTION_REFUSED (16:11:45:867 | error, network)
at http://127.0.0.1:8081/api
failed to get API response: [object Object] (16:11:45:868)
Is this verbosity normal?
The second line shows that I caught the error (which I do not know how to display correctly yet).