For some reason I dont see any errors (like syntax error) when they appear inside 'finally' block of a promise. Why is that?
angular.module('App', [])
.controller('AppCtrl', function(TestService) {
TestService.outerMethod().then(function() {
console.log('Success')
}, function(error) {
console.error('Error')
})
})
.service('TestService', function($q) {
this.outerMethod = outerMethod;
function innerMethod() {
var deferred = $q.defer();
deferred.resolve();
return deferred.promise;
}
function outerMethod() {
var deferred = $q.defer();
// syntaxErrorVisible
innerMethod().finally(function() {
// syntaxErrorNotVisible
deferred.resolve();
});
return deferred.promise;
}
})
;
Codepen: http://codepen.io/anon/pen/vOJGpG
The problem is that, when we uncomment those comments, that occur syntax errors, we wont wee any errors (in browser console) when errors is placed inside 'finally' block of this code.
The problem is the way you return the promise:
On this line you just returned the original promise. Your caller knows nothing about the
finally
attached to it. In order to keep the chain, you need to return the promise returned byfinally
:Updated Pen