2016-07-11 97 views
1

下面是我的雲代碼,我試圖用它來創建一個朋友數據庫,第一個和第三個函數都正常工作,但AcceptFriendRequest函數超時,好像沒有那裏的服務器的錯誤代碼爲100.我非常失敗,因爲這發生在100%的時間。所有的幫助表示讚賞。解析連接超時只有一個特定的功能

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

var FriendRequest = Parse.Object.extend("FriendsIncoming"); 

var FRequest = new FriendRequest(); 

var user = request.user; 

var query = new Parse.Query(Parse.User); 
query.equalTo("username", request.params.username); 
query.find({ 
    success: function (people) { 
     if(people.length == 0) 
     { 
      response.success(-5); 
      return; 
     } 

     var person = people[0]; 
     FRequest.set("OwnerID", user.id); 
     FRequest.set("TargetFriend", person.id); 
     FRequest.set("Status", 0); 

     var query = new Parse.Query("FriendsIncoming"); 
     query.equalTo("OwnerID", user.id); 
     query.equalTo("TargetFriendID", person.id); 
     query.find({ 
      success: function (results) { 

       if (results.length > 0) { 
        response.success(1); 
        return; 
       } 
       FRequest.save(null, { 
        success: function (Friend) { 
         response.success(2); 
        }, 
        error: function (Friend, error) { 
         response.error(3); 
        } 
       }); 
       response.error(-2); 

      }, 
      error: function() { 
       response.error(-1); 
      } 
     }); 
    } 
    , 
    error: function (Friend, error) { 
     response.error(-4); 
    } 

}); 


}); 

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


var user = request.user; 

var query = new Parse.Query("FriendsIncoming"); 
query.equalTo("OwnerID", user.id); 
query.equalTo("TargetFriendID", request.params.TargetFriendID); 
query.find({ 
    success: function (results) { 

     if (results.length > 0) { 

      response.success(1); 
      return; 
     } 
     FRequest.save(null, { 
      success: function (Friend) { 
       response.success(2); 
      }, 
      error: function (Friend, error) { 
       response.error(3); 
      } 
     }); 
     response.error(-2); 

    }, 
    error: function() { 
     response.error(-1); 
    } 
}); 
}); 




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

var query = new Parse.Query("FriendsAccepted"); 
var results = []; 


query.find().then(function (Friends) { 
for (var i = 0; i < Friends.length; i++) { 
results.push(Friends[i]); 
} 

// success has been moved inside the callback for query.find() 
response.success(results); 
}, function (error) { 
// Make sure to catch any errors, otherwise you may see a "success/error not called" error in Cloud Code. 
response.error("Could not retrieve Posts, error " + error.code + ": " + error.message); 
}); 
}); 

回答

0

這似乎是FRequest在AcceptFriendRequest沒有初始化... 在函數內部添加此。 parse.com上的超時時間爲15秒,對於雲端功能和afterSave 3秒。他們可能會改變它,雖然因爲他們正在關閉

var FriendRequest = Parse.Object.extend("FriendsIncoming"); 
var FRequest = new FriendRequest();