Skip to content

Commit 645d98e

Browse files
committed
Make onError a required prop
1 parent db26b7d commit 645d98e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

modules/components/Routes.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ function queryIsActive(activeQuery, query) {
189189
return true;
190190
}
191191

192+
function defaultTransitionErrorHandler(error) {
193+
// Throw so we don't silently swallow async errors.
194+
throw error; // This error probably originated in a transition hook.
195+
}
196+
192197
/**
193198
* The <Routes> component configures the route hierarchy and renders the
194199
* route matching the current location when rendered into a document.
@@ -205,13 +210,14 @@ var Routes = React.createClass({
205210
initialPath: React.PropTypes.string,
206211
initialMatches: React.PropTypes.array,
207212
onChange: React.PropTypes.func,
208-
onError: React.PropTypes.func
213+
onError: React.PropTypes.func.isRequired
209214
},
210215

211216
getDefaultProps: function () {
212217
return {
213218
initialPath: null,
214-
initialMatches: []
219+
initialMatches: [],
220+
onError: defaultTransitionErrorHandler
215221
};
216222
},
217223

@@ -267,12 +273,7 @@ var Routes = React.createClass({
267273

268274
this.dispatch(path, function (error, abortReason, nextState) {
269275
if (error) {
270-
if (this.props.onError) {
271-
this.props.onError.call(this, error);
272-
} else {
273-
// Throw so we don't silently swallow errors.
274-
throw error; // This error probably originated in a transition hook.
275-
}
276+
this.props.onError.call(this, error);
276277
} else if (abortReason instanceof Redirect) {
277278
this.replaceWith(abortReason.to, abortReason.params, abortReason.query);
278279
} else if (abortReason) {

0 commit comments

Comments
 (0)