Skip to content

Commit

Permalink
Inline error/abort handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Oct 9, 2014
1 parent 9ccebac commit c45909a
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions modules/components/Routes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var React = require('react');
var warning = require('react/lib/warning');
var invariant = require('react/lib/invariant');
var canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM;
var copyProperties = require('react/lib/copyProperties');
var HashLocation = require('../locations/HashLocation');
var reversedArray = require('../utils/reversedArray');
Expand Down Expand Up @@ -261,36 +260,6 @@ function computeHandlerProps(matches, query) {
return props;
}

var BrowserTransitionHandling = {

handleError: function (component, error) {
throw error; // This error probably originated in a transition hook.
},

handleAbort: function (component, reason) {
if (reason instanceof Redirect) {
component.replaceWith(reason.to, reason.params, reason.query);
} else {
component.goBack();
}
}

};

var ServerTransitionHandling = {

handleError: function (component, error) {
// TODO
},

handleAbort: function (component, reason) {
// TODO
}

};

var TransitionHandling = canUseDOM ? BrowserTransitionHandling : ServerTransitionHandling;

var ActiveContext = require('../mixins/ActiveContext');
var LocationContext = require('../mixins/LocationContext');
var RouteContext = require('../mixins/RouteContext');
Expand Down Expand Up @@ -348,9 +317,12 @@ var Routes = React.createClass({

this.dispatch(path, actionType, function (error, abortReason) {
if (error) {
TransitionHandling.handleError(this, error);
// Throw so we don't silently swallow errors.
throw error; // This error probably originated in a transition hook.
} else if (abortReason instanceof Redirect) {
this.replaceWith(abortReason.to, abortReason.params, abortReason.query);
} else if (abortReason) {
TransitionHandling.handleAbort(this, abortReason);
this.goBack();
} else {
this.updateScroll(path, actionType);

Expand Down

0 comments on commit c45909a

Please sign in to comment.