Search code examples
ibm-mobilefirstjsonstore

How to read server response when calling push/pushSelected methods from Worklight JSONStore?


I`m trying to find out how to get the server response when I call the JSONStore push/pushSelected functions. I know that I can handle succes using:

.then(function (res) {
    //handle success
    //res is an empty array if all documents reached the server
    //res is an array of error responses if some documents failed to reach the server
})

But what I really want is to read the server response, that has important information for me.

I even tried using an onSuccess callback (below code), but it didn't work too.

var options = {
    onSuccess: function(response){
        WL.Logger.debug("response: "+JSON.stringify(response));
    }
};
myCollection.pushSelected(doc, options)
.then(function (res){
     ...
});

It prints "response: 0"

Is there a way that I can do that?

Thank you in advance.


Solution

  • You can read the response from the adapter in the accept function.

    accept: function (adapterResponse) { return (adapterResponse.status === 200); }

    There's an example in the WL.JSONStore.init documentation page.

    If you want something else, I suggest a feature request.