Skip to content

Commit

Permalink
Merge pull request tildeio#202 from tildeio/revert-201-error-improvement
Browse files Browse the repository at this point in the history
Revert "Improve errors"
  • Loading branch information
rwjblue authored Nov 7, 2016
2 parents f582cb8 + 95f2df8 commit b312ebe
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 103 deletions.
9 changes: 4 additions & 5 deletions lib/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import RouteRecognizer from 'route-recognizer';
import { Promise } from 'rsvp';
import { trigger, log, slice, forEach, merge, extractQueryParams, getChangelist, promiseLabel, callHook } from './utils';
import TransitionState from './transition-state';
import { logAbort, Transition } from './transition';
import TransitionAbortedError from './transition-aborted-error';
import { logAbort, Transition, TransitionAborted } from './transition';
import NamedTransitionIntent from './transition-intent/named-transition-intent';
import URLTransitionIntent from './transition-intent/url-transition-intent';

Expand Down Expand Up @@ -495,15 +494,15 @@ function handlerEnteredOrUpdated(currentHandlerInfos, handlerInfo, enter, transi
}

if (transition && transition.isAborted) {
throw new TransitionAbortedError();
throw new TransitionAborted();
}

handler.context = context;
callHook(handler, 'contextDidChange');

callHook(handler, 'setup', context, transition);
if (transition && transition.isAborted) {
throw new TransitionAbortedError();
throw new TransitionAborted();
}

currentHandlerInfos.push(handlerInfo);
Expand Down Expand Up @@ -695,7 +694,7 @@ function finalizeTransition(transition, newState) {
// Resolve with the final handler.
return handlerInfos[handlerInfos.length - 1].handler;
} catch(e) {
if (!(e instanceof TransitionAbortedError)) {
if (!(e instanceof TransitionAborted)) {
//var erroneousHandler = handlerInfos.pop();
var infos = transition.state.handlerInfos;
transition.trigger(true, 'error', e, transition, infos[infos.length-1].handler);
Expand Down
27 changes: 0 additions & 27 deletions lib/router/transition-aborted-error.js

This file was deleted.

12 changes: 8 additions & 4 deletions lib/router/transition.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Promise } from 'rsvp';
import { trigger, slice, log, promiseLabel } from './utils';
import TransitionAbortedError from './transition-aborted-error';

/**
A Transition is a thennable (a promise-like object) that represents
Expand Down Expand Up @@ -326,11 +325,16 @@ Transition.prototype.send = Transition.prototype.trigger;
/**
@private
Logs and returns an instance of TransitionAbortedError.
Logs and returns a TransitionAborted error.
*/
function logAbort(transition) {
log(transition.router, transition.sequence, "detected abort.");
return new TransitionAbortedError();
return new TransitionAborted();
}

export { Transition, logAbort, TransitionAbortedError as TransitionAborted };
function TransitionAborted(message) {
this.message = (message || "TransitionAborted");
this.name = "TransitionAborted";
}

export { Transition, logAbort, TransitionAborted };
26 changes: 7 additions & 19 deletions lib/router/unrecognized-url-error.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { oCreate } from './utils';

/**
Promise reject reasons passed to promise rejection
handlers for failed transitions.
*/
function UnrecognizedURLError(message) {
if (!(this instanceof UnrecognizedURLError)) {
return new UnrecognizedURLError(message);
}

let error = Error.call(this, message);

if (Error.captureStackTrace) {
Error.captureStackTrace(this, UnrecognizedURLError);
} else {
this.stack = error.stack;
}

this.description = error.description;
this.fileName = error.fileName;
this.lineNumber = error.lineNumber;
this.message = error.message || 'UnrecognizedURL';
this.name = 'UnrecognizedURLError';
this.number = error.number;
this.code = error.code;
this.message = (message || "UnrecognizedURLError");
this.name = "UnrecognizedURLError";
Error.call(this);
}

UnrecognizedURLError.prototype = oCreate(Error.prototype);
Expand Down
24 changes: 13 additions & 11 deletions test/tests/router_test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
module,
test,
flushBackburner,
transitionTo,
transitionToWithAbort,
shouldNotHappen,
assertAbort
} from 'tests/test_helpers';
import { module, test, flushBackburner, transitionTo, transitionToWithAbort, shouldNotHappen } from "tests/test_helpers";
import Router from "router";
import { reject, Promise } from "rsvp";

Expand Down Expand Up @@ -1723,6 +1715,12 @@ test("can redirect from error handler", function(assert) {
});
});

function assertAbort(assert) {
return function _assertAbort(e) {
assert.equal(e.name, "TransitionAborted", "transition was aborted");
};
}

test("can redirect from setup/enter", function(assert) {
assert.expect(5);

Expand Down Expand Up @@ -1969,7 +1967,9 @@ test("willTransition function fired with cancellable transition passed in", func
transition.abort();
};

return router.transitionTo('about').then(shouldNotHappen(assert), assertAbort(assert));
return router.transitionTo('about').then(shouldNotHappen(assert), function(e) {
assert.equal(e.name, 'TransitionAborted', 'reject object is a TransitionAborted');
});
});
});

Expand All @@ -1996,7 +1996,9 @@ test("transitions can be aborted in the willTransition event", function(assert)
};

router.handleURL('/index').then(function() {
return router.transitionTo('about').then(shouldNotHappen(assert), assertAbort(assert));
return router.transitionTo('about').then(shouldNotHappen(assert), function(e) {
assert.equal(e.name, 'TransitionAborted', 'reject object is a TransitionAborted');
});
});
});

Expand Down
21 changes: 4 additions & 17 deletions test/tests/test_helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Backburner } from "backburner";
import { resolve, configure } from "rsvp";
import { oCreate } from 'router/utils';
import TransitionAbortedError from 'router/transition-aborted-error';

var slice = Array.prototype.slice;

Expand Down Expand Up @@ -40,11 +39,6 @@ function module(name, options) {
});
}

function assertAbort(assert) {
return function _assertAbort(e) {
assert.ok(e instanceof TransitionAbortedError, 'transition was redirected/aborted');
};
}

// Helper method that performs a transition and flushes
// the backburner queue. Helpful for when you want to write
Expand All @@ -57,7 +51,9 @@ function transitionTo(router) {

function transitionToWithAbort(assert, router) {
var args = slice.call(arguments, 2);
router.transitionTo.apply(router, args).then(shouldNotHappen, assertAbort(assert));
router.transitionTo.apply(router, args).then(shouldNotHappen, function(reason) {
assert.equal(reason.name, "TransitionAborted", "transition was redirected/aborted");
});
flushBackburner();
}

Expand All @@ -83,13 +79,4 @@ test("backburnerized testing works as expected", function(assert) {
});
});

export {
module,
test,
flushBackburner,
transitionTo,
transitionToWithAbort,
shouldNotHappen,
stubbedHandlerInfoFactory,
assertAbort
};
export { module, test, flushBackburner, transitionTo, transitionToWithAbort, shouldNotHappen, stubbedHandlerInfoFactory };
20 changes: 0 additions & 20 deletions test/tests/transition-aborted-error_test.js

This file was deleted.

0 comments on commit b312ebe

Please sign in to comment.