@@ -58,6 +58,8 @@ export class Transition implements IHookRegistry {
58
58
59
59
/** @hidden */
60
60
private _deferred = services . $q . defer ( ) ;
61
+ /** @hidden */
62
+ private _error : any ;
61
63
/**
62
64
* This promise is resolved or rejected based on the outcome of the Transition.
63
65
*
@@ -156,7 +158,7 @@ export class Transition implements IHookRegistry {
156
158
/**
157
159
* Determines whether two transitions are equivalent.
158
160
*/
159
- is ( compare : ( Transition | { to : any , from : any } ) ) : boolean {
161
+ is ( compare : ( Transition | { to ? : any , from ? : any } ) ) : boolean {
160
162
if ( compare instanceof Transition ) {
161
163
// TODO: Also compare parameters
162
164
return this . is ( { to : compare . $to ( ) . name , from : compare . $from ( ) . name } ) ;
@@ -474,6 +476,7 @@ export class Transition implements IHookRegistry {
474
476
trace . traceError ( reason , this ) ;
475
477
this . success = false ;
476
478
this . _deferred . reject ( reason ) ;
479
+ this . _error = reason ;
477
480
runSynchronousHooks ( hookBuilder . getOnErrorHooks ( ) , true ) ;
478
481
} ;
479
482
@@ -499,13 +502,16 @@ export class Transition implements IHookRegistry {
499
502
* @returns true if the Transition is valid
500
503
*/
501
504
valid ( ) {
502
- return ! this . error ( ) ;
505
+ return ! this . error ( ) || this . success !== undefined ;
503
506
}
504
507
505
508
/**
506
- * The reason the Transition is invalid
509
+ * The Transition error reason.
510
+ *
511
+ * If the transition is invalid (and could not be run), returns the reason the transition is invalid.
512
+ * If the transition was valid and ran, but was not successful, returns the reason the transition failed.
507
513
*
508
- * @returns an error message explaining why the transition is invalid
514
+ * @returns an error message explaining why the transition is invalid, or the reason the transition failed.
509
515
*/
510
516
error ( ) {
511
517
let state : State = this . $to ( ) ;
@@ -514,6 +520,8 @@ export class Transition implements IHookRegistry {
514
520
return `Cannot transition to abstract state '${ state . name } '` ;
515
521
if ( ! Param . validates ( state . parameters ( ) , this . params ( ) ) )
516
522
return `Param values not valid for state '${ state . name } '` ;
523
+ if ( this . success === false )
524
+ return this . _error ;
517
525
}
518
526
519
527
/**
0 commit comments