Merge 1.0.0 changes back to master.

This commit is contained in:
Nick Couchman
2018-10-05 15:31:01 -04:00
3 changed files with 65 additions and 16 deletions

View File

@@ -92,6 +92,33 @@ angular.module('rest').factory('requestService', ['$injector',
});
};
/**
* Creates a promise error callback which resolves the promise with the
* given default value only if the @link{Error} in the original rejection
* is a NOT_FOUND error. All other errors are passed through and must be
* handled as yet more rejections.
*
* @param {*} value
* The default value to use to resolve the promise if the promise is
* rejected with a NOT_FOUND error.
*
* @returns {Function}
* A function which can be provided as the error callback for a
* promise.
*/
service.defaultValue = function defaultValue(value) {
return service.createErrorCallback(function resolveIfNotFound(error) {
// Return default value only if not found
if (error.type === Error.Type.NOT_FOUND)
return value;
// Reject promise with original error otherwise
throw error;
});
};
/**
* Promise error callback which ignores all rejections due to REST errors,
* but logs all other rejections, such as those due to JavaScript errors.