Call to server method is not returning an error or result to client callback


#1

In my relatively simple code below, if I make the call in the client the client console immediately outputs ‘callback executing’. However, I never see the error or result which should also be logged in the client’s callback. My other Meteor.call functions all work as expected. I can’t pinpoint what I am doing wrong here, any ideas?

Client

Meteor.call('saveProject', LocalProject.findOne(currentEditingProjectID), function(error, result) {
    console.log('callback executing');
    
    if(error)console.log(error);
    if (result) {
        //do stuff...
        console.log(result)
    }
})

Server

'saveProject': function(data) {
    if (!this.userId) {
        throw new Meteor.Error(403, 'You must be logged in to save projects');
    }
    //validate data

    //update modified time
    data.meta.modified = new Date();

    //perform save
    return allProjects.update(data._id, data, function(error, result) {
        if (error) {
            console.log(error)
            throw new Meteor.Error(500, 'Save failed');
        }
        if (result) {
            console.log(result)
        }
    });
}

#2

Your method probably returns 0, hence no message is displayed (because both error and result are falsey).


#3

I see what you mean Steve, thanks for the pointer. I think you are right in that a falsey value was being returned.

I was not running the method on the server sync and the client callback was executing before I had any data to return from the update function. Update for me, in this situation, should always return 1 but clearly it wasn’t.

Here is how I fixed it:

var syncUpdate = Meteor.wrapAsync(allProjects.update,allProjects);
returnValue=syncUpdate(data._id,data);
return returnValue;

So now my client logs 1 (since I update 1 document per save) and I can do my other UI work knowing the project was saved.