Skip to content

Commit d0f1748

Browse files
committed
Refactoring to improve error messaging.
1 parent d2ced6b commit d0f1748

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/state.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
2020
// inherit 'data' from parent and override by own values (if any)
2121
data: function(state) {
2222
if (state.parent && state.parent.data) {
23-
state.data = state.self.data = angular.extend({}, state.parent.data, state.data);
23+
state.data = state.self.data = extend({}, state.parent.data, state.data);
2424
}
2525
return state.data;
2626
},
@@ -105,11 +105,14 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
105105
}
106106
};
107107

108+
function isRelative(stateName) {
109+
return stateName.indexOf(".") === 0 || stateName.indexOf("^") === 0;
110+
}
108111

109112
function findState(stateOrName, base) {
110113
var isStr = isString(stateOrName),
111114
name = isStr ? stateOrName : stateOrName.name,
112-
path = name.indexOf(".") === 0 || name.indexOf("^") === 0;
115+
path = isRelative(name);
113116

114117
if (path) {
115118
if (!base) throw new Error("No reference point given for path '" + name + "'");
@@ -215,7 +218,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
215218
options = extend({ location: true, inherit: false, relative: null }, options);
216219

217220
var toState = findState(to, options.relative);
218-
if (!isDefined(toState)) throw new Error("No such state " + toState);
221+
222+
if (!isDefined(toState)) {
223+
if (options.relative) throw new Error("Could not resolve '" + to + "' from state '" + options.relative + "'");
224+
throw new Error("No such state '" + to + "'");
225+
}
219226
if (toState['abstract']) throw new Error("Cannot transition to abstract state '" + to + "'");
220227
if (options.inherit) toParams = inheritParams($stateParams, toParams || {}, $state.$current, toState);
221228
to = toState;

0 commit comments

Comments
 (0)