var dispatcher = require('../dispatcher');
function preServiceCall(config){
  dispatcher.handleViewAction({
    data: {[config.node]: undefined},
    type: config.type,
    status: {[config.node]: {name:config.preStatus}, isLoading: true}
  });
}
function postServiceCall(config, json){
  dispatcher.handleServerAction({
    data: {[config.node]: json},
    type: config.type,
    status: {[config.node]: {name:config.status}, isLoading: false}
  });
}

module.exports = function(config){
  config = config || {};
  config.type = config.type || 'update';
  config.preStatus = config.preStatus || 'loading';
  if(!config.service){
    throw new Error('You need to provide a service to call');
  }
  if(!config.status){
    throw new Error('You need to provide a status to your action');
  }
  /*if(!config.data){
    throw new Error('You need to provide an action data');
  }*/
  //Exposes a function consumes by the compoennt.
  return function(criteria){
    preServiceCall(config);
    //todo: add middleware see slack for more informations
    return config.service(criteria).then(function(jsonData){
      postServiceCall(config, jsonData);
    }, function actionError(err){
      console.warn('Error in action', err);
      //Get code back from a project
      throw new Error('An errror occurs');
    });
  };
};

@@ -36,16 +36,53 @@
 cher');%0A
+var message = require('../message');%0A
 function
@@ -484,16 +484,329 @@
  %7D);%0A%7D%0A%0A
+/***/%0Afunction errorOnCall(config, err)%7B%0A  if(err.statusCode === 422)%7B%0A    dispatcher.handleServerAction(%7B%0A      data: %7B%5Bconfig.node%5D: err%7D,%0A      type: 'updateError',%0A      status: %7B%5Bconfig.node%5D: %7Bname:config.status%7D, isLoading: false%7D%0A    %7D);%0A  %7Delse %7B%0A    message.addErrorMessage(JSON.stringify(err));%0A  %7D%0A%7D%0A%0A
 module.e
@@ -1566,16 +1566,48 @@
 , err);%0A
+      errorOnCall(config, err);%0A
       //
@@ -1635,22 +1635,24 @@
 project%0A
-
       
+//
 throw ne

Add error handling.