简体   繁体   English

解析Cloud JS脚本-错误代码:141

[英]Parse Cloud JS Script - Error Code: 141

I've written up a Parse Cloud script in JS which gets called in my Objective-C app. 我已经用JS编写了一个Parse Cloud脚本,该脚本在我的Objective-C应用程序中被调用。 When the script gets called I get an error with the code: 141. Here is the code, it gets called when a user accepts a friend request from another user (I'm also not entirely familiar with JS either): 当脚本被调用时,我收到一个代码错误:141。这是代码,当用户接受另一个用户的朋友请求时,它就会被调用(我也不完全熟悉JS):

Parse.Cloud.define("addFriendToFriendsRelation", function(request, response) {

Parse.Cloud.useMasterKey();

var friendRequestId = request.params.friendRequest;
var query = new Parse.Query("FriendRequest");

//get the friend request object
query.get(friendRequestId, {

    success: function(friendRequest) {

        //get the user the request was from
        var fromUser = friendRequest.get("from");
        //get the user the request is to
        var toUser = friendRequest.get("to");

        var relation = fromUser.relation("friends");
        //add the user the request was to (the accepting user) to the fromUsers friends
        relation.add(toUser);

        //save the fromUser
        fromUser.save(null, {

            success: function() {

                //saved the user, now edit the request status and save it
                friendRequest.set("status", "accepted");
                friendRequest.save(null, {

                    success: function() {

                        response.success("saved relation and updated friendRequest");
                    }, 

                    error: function(error) {

                        response.error(error);
                    }

                });

            },

            error: function(error) {

             response.error(error);

            }

        });

    },

    error: function(error) {

        response.error(error);

    }

});

});

All help and suggestions are greatly appreciated. 非常感谢所有帮助和建议。 Thank you. 谢谢。

EDIT: In my code I am calling: 编辑:在我的代码中我正在调用:

[PFCloud callFunctionInBackground:@"addFriendToFriendsRelation" withParameters:@{@"friendRequest" : friendRequest.objectId} block:^(id object, NSError *error) {

EDIT2: The error I am getting in the JS script is the last EDIT2:我在JS脚本中遇到的错误是最后一个

        error: function(error) {

        response.error(error);

    }

to be called. 被称为。

This will solve your problem , all you have to do is 这将解决您的问题,您所要做的就是

add

useMasterKey: true

in the find method. 在查找方法中。 change your code to this 将您的代码更改为此

Parse.Cloud.define("addFriendToFriendsRelation", function(request, response) {

Parse.Cloud.useMasterKey();

var friendRequestId = request.params.friendRequest;
var query = new Parse.Query("FriendRequest");

//get the friend request object
query.get(friendRequestId, {

   useMasterKey: true, success: function(friendRequest) {

        //get the user the request was from
        var fromUser = friendRequest.get("from");
        //get the user the request is to
        var toUser = friendRequest.get("to");

        var relation = fromUser.relation("friends");
        //add the user the request was to (the accepting user) to the fromUsers friends
        relation.add(toUser);

        //save the fromUser
        fromUser.save(null, {

            success: function() {

                //saved the user, now edit the request status and save it
                friendRequest.set("status", "accepted");
                friendRequest.save(null, {

                    success: function() {

                        response.success("saved relation and updated friendRequest");
                    }, 

                    error: function(error) {

                        response.error(error);
                    }

                });

            },

            error: function(error) {

             response.error(error);

            }

        });

    },

    error: function(error) {

        response.error(error);

    }

});

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM