I’m trying to reproduce second code sample from documentation
https://backendless.com/documentation/business-logic/js/bl_sync_vs_async_code.htm
here is my code:
Backendless.enablePromises();
Backendless.ServerCode.Persistence.afterCreate('tableTwo', function (req, res) {
var PostsStore = Backendless.Data.of('tableOne');
return PostsStore.findById('972B0117-12B6-EB2D-FF1E-28171D4C5900')
.then(post => {
post.colInt += 1;
post.colStr = (new Date()).toISOString();
return PostsStore.save(post);
})
.catch(err => {
return Promise.reject('Unable to save post. Got an error : ' + err.message)
});
}, true);
and here is my code in client:
Backendless.enablePromises();
Backendless.Persistence.of( 'tableTwo' ).save({colInt:999})
.then(
function(objRet){
console.log('saved tableTwo ok: ' + JSON.stringify(objRet));
})
.catch(
function(err){
console.log('saved tableTwo err: ' + JSON.stringify(err));
});
So, when I use async version of afterCreate (with “,true” after function) - I don’t get catch, I always get only “success” function run, even when I have errors (for example if I removed necessary permissions).
Only when I comment out /",true"/ I have working catch()