fnpjs: actions - handle exception in action.getState gracefully
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 14 Apr 2014 14:33:26 +0000 (16:33 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 23 Apr 2014 11:05:05 +0000 (13:05 +0200)
src/fnpjs/actions.js

index d369ff0..c49373a 100644 (file)
@@ -3,7 +3,11 @@ define(function(require) {
 'use strict';
 
 var _ = require('libs/underscore'),
 'use strict';
 
 var _ = require('libs/underscore'),
-    Backbone = require('libs/backbone');
+    Backbone = require('libs/backbone'),
+    logging = require('fnpjs/logging/logging');
+
+var logger = logging.getLogger('fnpjs.actions');
+
 
 var Action = function(fqName, definition, config, appObject) {
     this.fqName = fqName;
 
 var Action = function(fqName, definition, config, appObject) {
     this.fqName = fqName;
@@ -52,7 +56,12 @@ _.extend(Action.prototype, Backbone.Events, {
     getState: function() {
         var gotState;
         if(!this._cache) {
     getState: function() {
         var gotState;
         if(!this._cache) {
-            gotState = this.definition.getState.call(this, this.params);
+            try {
+                gotState = this.definition.getState.call(this, this.params);
+            } catch(e) {
+                logger.exception(e);
+                return;
+            }
             if(typeof gotState === 'boolean') {
                 gotState = {allowed: gotState};
             }
             if(typeof gotState === 'boolean') {
                 gotState = {allowed: gotState};
             }