Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored error handling based on code review by @nciagra

  • Loading branch information...
commit 92798848697bdfcd90d5dffd9e1cb1d615d8ffc3 1 parent 57ca201
@snookca snookca authored
View
22 lib/batman.js
@@ -6878,8 +6878,7 @@
};
Dispatcher.prototype.dispatch = function(params) {
- var inferredParams, isPrevented, path, route, _ref,
- _this = this;
+ var error, inferredParams, path, route, _ref, _ref1;
inferredParams = this.constructor.paramsFromArgument(params);
route = this.routeForParams(inferredParams);
if (route) {
@@ -6894,16 +6893,17 @@
} else {
this.get('app.currentParams').clear();
}
- isPrevented = false;
- if (Batman.currentApp) {
- Batman.currentApp.fire('error', {
- type: '404',
- preventDefault: function() {
- return isPrevented = true;
- }
- });
+ error = {
+ type: '404',
+ isPrevented: false,
+ preventDefault: function() {
+ return this.isPrevented = true;
+ }
+ };
+ if ((_ref1 = Batman.currentApp) != null) {
+ _ref1.fire('error', error);
}
- if (isPrevented) {
+ if (error.isPrevented) {
return params;
}
if (params !== '/404') {
View
22 lib/dist/batman.node.js
@@ -6878,8 +6878,7 @@
};
Dispatcher.prototype.dispatch = function(params) {
- var inferredParams, isPrevented, path, route, _ref,
- _this = this;
+ var error, inferredParams, path, route, _ref, _ref1;
inferredParams = this.constructor.paramsFromArgument(params);
route = this.routeForParams(inferredParams);
if (route) {
@@ -6894,16 +6893,17 @@
} else {
this.get('app.currentParams').clear();
}
- isPrevented = false;
- if (Batman.currentApp) {
- Batman.currentApp.fire('error', {
- type: '404',
- preventDefault: function() {
- return isPrevented = true;
- }
- });
+ error = {
+ type: '404',
+ isPrevented: false,
+ preventDefault: function() {
+ return this.isPrevented = true;
+ }
+ };
+ if ((_ref1 = Batman.currentApp) != null) {
+ _ref1.fire('error', error);
}
- if (isPrevented) {
+ if (error.isPrevented) {
return params;
}
if (params !== '/404') {
View
16 src/routing/dispatcher.coffee
@@ -70,15 +70,13 @@ class Batman.Dispatcher extends Batman.Object
else
@get('app.currentParams').clear()
- isPrevented = false
- if Batman.currentApp
- Batman.currentApp.fire 'error', {
- type: '404'
- preventDefault: =>
- isPrevented = true
- }
-
- return params if isPrevented
+ error =
+ type: '404'
+ isPrevented: false
+ preventDefault: -> @isPrevented = true
+
+ Batman.currentApp?.fire 'error', error
+ return params if error.isPrevented
return Batman.redirect('/404') unless params is '/404'
path
Please sign in to comment.
Something went wrong with that request. Please try again.