Closed omdathetkan closed 9 years ago
This pull request is more to show my point, maybe you did not implement it this way for a reason.
I see that you have a way to intentionally send back exceptions:
if(err){ callback(null, 'exception', err); }else{ callback({ success: true, data: rows, total: rowsTotal[0].totals }); }
But this is not really in line with the standard node callback(err, results) convention. Why not do:
if(err){ callback(err); }else{ callback(null, { data: rows, total: rowsTotal[0].totals }); }
This way you might be able to pass the callback to a lot of standard functions directly. And maybe even automatically set success:true if error is null?
To use this, do:
var directCfg = { namespace: "ExtRemote", apiName: "REMOTING_API", apiPath: "/directapi", classPath: "/direct", classPrefix: "DX", relativeUrl: true, appendRequestResponseObjects: true, conventionalCallbackFormat: true, autoSetSuccess: true }; // Now you can do: // [...] read: function(params, callback, sessionID, request, response) { models.Foo.findAll({raw: true}).complete(callback); } // Instead off read: function(params, callback, sessionID, request, response) { models.Foo.findAll({raw: true}).complete(function(err,results) { callback(results); }); } // [...]
Feature implemented in version 2
This pull request is more to show my point, maybe you did not implement it this way for a reason.
I see that you have a way to intentionally send back exceptions:
But this is not really in line with the standard node callback(err, results) convention. Why not do:
This way you might be able to pass the callback to a lot of standard functions directly. And maybe even automatically set success:true if error is null?
To use this, do: