jacomyal / domino.js

[deprecated] A JavaScript cascading controller for fast interactive Web interfaces prototyping.
https://jacomyal.github.io/domino.js
MIT License
54 stars 7 forks source link

Add global/local hooks to catch services responses #6

Closed jacomyal closed 11 years ago

jacomyal commented 11 years ago

Would be nice to make it possible to catch services for one instance or globally. Here is an example (with d a domino instance):

d.addAjaxHook('rpc', function(data) {
  if ((data || {}).result !== 'Ok') {
    this.warn('Unvalid response.');
    return false;
  } else
    return true;
});

Then, when a service returns a data object where data.result !== 'Ok', the related error callback will be triggered instead of the success callback, with the error message 'rpc'.

jacomyal commented 11 years ago

Instead of hooks modifying the data, I just implemented the expect feature for the services. It makes possible to intercept calls that return a 200 response, and redirect them to their respective error callback, depending on the data, the parameters given to the service and the related service definition.

It is possible to set expect in the service definition, while calling the service, in the instance settings or even in the global settings.