chore($q): convert thrown Error to $minErr when calling $q constructor without resolver

This commit is contained in:
Jeff Cross
2014-08-21 11:31:31 -07:00
parent a6bd4bc866
commit 1b331f3729
2 changed files with 19 additions and 2 deletions

View File

@@ -0,0 +1,17 @@
@ngdoc error
@name $q:norslvr
@fullName No resolver function passed to $Q
@description
Occurs when calling creating a promise using {@link $q} as a constructor, without providing the
required `resolver` function.
```
//bad
var promise = $q().then(doSomething);
//good
var promise = $q(function(resolve, reject) {
waitForSomethingAsync.then(resolve);
}).then(doSomething);
```

View File

@@ -235,6 +235,7 @@ function $$QProvider() {
* @returns {object} Promise manager.
*/
function qFactory(nextTick, exceptionHandler) {
var $qMinErr = minErr('$q');
function callOnce(self, resolveFn, rejectFn) {
var called = false;
function wrap(fn) {
@@ -522,8 +523,7 @@ function qFactory(nextTick, exceptionHandler) {
var $Q = function Q(resolver) {
if (!isFunction(resolver)) {
// TODO(@caitp): minErr this
throw new TypeError('Expected resolverFn');
throw $qMinErr('norslvr', "Expected resolverFn, got '{0}'", resolver);
}
if (!(this instanceof Q)) {