Below is a simplified version of the code I'm working with, running in CodePen for example:
var app = angular.module("httptest", []);
app.controller("getjson", ["$scope", "$http", function($scope, $http) {
$http.get("https://codepen.io/anon/pen/LVEwdw.js").
then((response) => {
console.log(response.data)
console.log('in then')
throw 'the error'
}).catch((e) => {
console.log('in the catch')
console.log(e);
});
}]);
I expected that if the catch()
block is executed, the error would not display in red on the console unless specifically logged. However, the error still appears in red before entering the catch()
block. I tried to create an equivalent example without using AngularJS's $http
where the behavior matched my expectation:
var promise1 = new Promise(function(resolve, reject) {
resolve();
});
promise1.then((result) => {
console.log('about to throw error')
throw 'hey'
}).catch(function(error) {
console.log(error);
});
In this alternative example, the error does not appear in red.
Why is the handled error displaying in red in the $http
scenario and how can it be suppressed?