Hi all.
I'm trying to use some promise library to avoid the callback hell working with ACS in Node. Q seems, for me, a little bit complex, but I found this Bluebird library that seems to be really simple to work.
Then I tried to use it with ACS to do a simple test (note: the queryAsync() function is an automatically cloned function of query but with promise properties by the PromisifyAll function):
var ACS = require('acs-node');
var Promise = require('bluebird');
var objects = Promise.promisifyAll(ACS.Objects);
objects.queryAsync({
classname: 'Groups',
where: {
'id': '123986sfg97ergjw9er7gyjw9'
},
response_json_depth: 1
}).then(function(data) {
console.log('Data: ' + JSON.stringify(data));
res.redirect('/home');
}).catch(function(e) {
//A client error like 400 Bad Request happened
console.log('Error: ' + JSON.stringify(e));
res.redirect('/error');
});
The problem here is that I never been able to enter in the then part of the promise. With that code, the catch part returns the Group object with its data. If I change the id to '1' to find nothing, the catch part returns an error message
Error: {'success':false,'error':true,code':400,'message':'Error: Invalid object id : 1'}
So, working or not, I always enter in the catch part.
Any ideas or any advice about promises with ACS?