@@ -36,6 +36,7 @@ import { UIRouter } from '../router';
36
36
import { UIInjector } from '../interface' ;
37
37
import { RawParams } from '../params/interface' ;
38
38
import { ResolvableLiteral } from '../resolve/interface' ;
39
+ import { Rejection } from './rejectFactory' ;
39
40
40
41
/** @hidden */
41
42
const stateSelf : ( _state : StateObject ) => StateDeclaration = prop ( 'self' ) ;
@@ -87,7 +88,7 @@ export class Transition implements IHookRegistry {
87
88
/** @hidden */
88
89
_aborted : boolean ;
89
90
/** @hidden */
90
- private _error : any ;
91
+ private _error : Rejection ;
91
92
92
93
/** @hidden Holds the hook registration functions such as those passed to Transition.onStart() */
93
94
_registeredHooks : RegisteredHooks = { } ;
@@ -703,7 +704,7 @@ export class Transition implements IHookRegistry {
703
704
runAllHooks ( getHooksFor ( TransitionHookPhase . SUCCESS ) ) ;
704
705
} ;
705
706
706
- const transitionError = ( reason : any ) => {
707
+ const transitionError = ( reason : Rejection ) => {
707
708
trace . traceError ( reason , this ) ;
708
709
this . success = false ;
709
710
this . _deferred . reject ( reason ) ;
@@ -770,20 +771,23 @@ export class Transition implements IHookRegistry {
770
771
* If the transition is invalid (and could not be run), returns the reason the transition is invalid.
771
772
* If the transition was valid and ran, but was not successful, returns the reason the transition failed.
772
773
*
773
- * @returns an error message explaining why the transition is invalid, or the reason the transition failed.
774
+ * @returns a transition rejection explaining why the transition is invalid, or the reason the transition failed.
774
775
*/
775
- error ( ) {
776
+ error ( ) : Rejection {
776
777
const state : StateObject = this . $to ( ) ;
777
778
778
- if ( state . self . abstract ) return `Cannot transition to abstract state '${ state . name } '` ;
779
+ if ( state . self . abstract ) {
780
+ return Rejection . invalid ( `Cannot transition to abstract state '${ state . name } '` ) ;
781
+ }
779
782
780
- const paramDefs = state . parameters ( ) ,
781
- values = this . params ( ) ;
783
+ const paramDefs = state . parameters ( ) ;
784
+ const values = this . params ( ) ;
782
785
const invalidParams = paramDefs . filter ( param => ! param . validates ( values [ param . id ] ) ) ;
786
+
783
787
if ( invalidParams . length ) {
784
- return `Param values not valid for state ' ${ state . name } '. Invalid params: [ ${ invalidParams
785
- . map ( param => param . id )
786
- . join ( ', ' ) } ]` ;
788
+ const invalidValues = invalidParams . map ( param => `[ ${ param . id } : ${ stringify ( values [ param . id ] ) } ]` ) . join ( ', ' ) ;
789
+ const detail = `The following parameter values are not valid for state ' ${ state . name } ': ${ invalidValues } ` ;
790
+ return Rejection . invalid ( detail ) ;
787
791
}
788
792
789
793
if ( this . success === false ) return this . _error ;
0 commit comments