mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-21 01:57:06 +08:00
chore($q): convert thrown Error to $minErr when calling $q constructor without resolver
This commit is contained in:
17
docs/content/error/$q/norslvr.ngdoc
Normal file
17
docs/content/error/$q/norslvr.ngdoc
Normal 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);
|
||||
```
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user