Improve error handling in JavaScript promises
This commit is contained in:
parent
1a1d51f427
commit
34d7a3bf52
|
@ -76,7 +76,10 @@
|
||||||
params: params
|
params: params
|
||||||
})
|
})
|
||||||
.success(deferred.resolve)
|
.success(deferred.resolve)
|
||||||
.error(deferred.reject);
|
.error(function(data, status) {
|
||||||
|
if (status == 404)
|
||||||
|
return deferred.reject();
|
||||||
|
});
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,11 +32,12 @@
|
||||||
* @desc The factory we'll use to register with Angular
|
* @desc The factory we'll use to register with Angular
|
||||||
* @returns the AddressBook constructor
|
* @returns the AddressBook constructor
|
||||||
*/
|
*/
|
||||||
AddressBook.$factory = ['$q', '$timeout', 'sgSettings', 'sgResource', 'sgCard', 'sgAcl', function($q, $timeout, Settings, Resource, Card, Acl) {
|
AddressBook.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'sgResource', 'sgCard', 'sgAcl', function($q, $timeout, $log, Settings, Resource, Card, Acl) {
|
||||||
angular.extend(AddressBook, {
|
angular.extend(AddressBook, {
|
||||||
$q: $q,
|
$q: $q,
|
||||||
$timeout: $timeout,
|
$timeout: $timeout,
|
||||||
$$resource: new Resource(Settings.activeUser.folderURL + '/Contacts', Settings.activeUser),
|
$log: $log,
|
||||||
|
$$resource: new Resource(Settings.activeUser.folderURL + 'Contacts', Settings.activeUser),
|
||||||
$Card: Card,
|
$Card: Card,
|
||||||
$$Acl: Acl,
|
$$Acl: Acl,
|
||||||
activeUser: Settings.activeUser
|
activeUser: Settings.activeUser
|
||||||
|
@ -204,7 +205,7 @@
|
||||||
/**
|
/**
|
||||||
* @function $rename
|
* @function $rename
|
||||||
* @memberof AddressBook.prototype
|
* @memberof AddressBook.prototype
|
||||||
* @desc Rename the addressbook
|
* @desc Rename the addressbook and keep the list sorted
|
||||||
* @param {string} name - the new name
|
* @param {string} name - the new name
|
||||||
* @returns a promise of the HTTP operation
|
* @returns a promise of the HTTP operation
|
||||||
*/
|
*/
|
||||||
|
@ -296,10 +297,12 @@
|
||||||
_this.$acl = new AddressBook.$$Acl('Contacts/' + _this.id);
|
_this.$acl = new AddressBook.$$Acl('Contacts/' + _this.id);
|
||||||
});
|
});
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
|
_this.isError = true;
|
||||||
|
if (angular.isObject(data)) {
|
||||||
AddressBook.$timeout(function() {
|
AddressBook.$timeout(function() {
|
||||||
angular.extend(_this, data);
|
angular.extend(_this, data);
|
||||||
_this.isError = true;
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue