2016-03-04 31 views
0

我將我的解析應用程序移至Heroku和MongoLab。除了我的雲代碼查詢之外,一切正常。無論我調用哪個查詢,都會調用錯誤塊,並且錯誤對象是未定義的。解析服務器雲代碼 - 先前正在運行的查詢全部返回未定義的錯誤

例子查詢:

Parse.Cloud.beforeDelete("Project", function(request, response) { 

    Parse.Cloud.useMasterKey(); 

    var projectId = request.object.id; 

    var Project = Parse.Object.extend("Project");  
    var query = new Parse.Query(Project); 

     query.get(projectId, { 
      success: function(project) { 

       //do some stuff with project 
       response.success("Success!"); 

      }, 
      error: function(error) { 
       console.log("Error Querying Deleted Project"); 
       response.error("Error!"); 
      } 

     }); 

}); 

這不只是這個查詢,其他查詢不工作要麼。這些查詢在Parse.com上託管時正在運行。我沒有改變它們。

編輯:

所以我改變了我的語法從error: function(error)error: function(model, error)和我最終得到一個錯誤,我研究了一點,現在我在點我在那裏我認識到,我的項目類(我試圖在上面操作)從未獲得任何類型的許可。沒有角色或ACL附加到它。

這裏是我如何創建我的角色:

var roleName = "hasSound_" + ident; 
var projectRole = new Parse.Role(roleName, new Parse.ACL()); 
projectRole.getUsers().add(creator); 

return projectRole.save().then(function(role) { 

    var acl = new Parse.ACL(); 
    acl.setReadAccess(role, true); //give read access to Role 
    acl.setWriteAccess(role, true); //give write access to Role 

    project.setACL(acl);    
    project.save(); 

    }); 

而這裏的錯誤的請求嘗試創建Parse.Role當我越來越:

Mar 04 14:39:32 ancient-lake-41070 heroku/router: at=info method=POST path="/parse/classes/_Role" host=ancient-lake-41070.herokuapp.com request_id=82af3849-842a-406f-8a4b-5f573e08a1e1 fwd="54.145.36.110" dyno=web.1 connect=0ms service=6ms status=400 bytes=578

回答

1

你的問題可能是你不應該在分析服務器上使用Parse.Cloud.useMasterKey()。相反,您應該在查詢中設置主密鑰,如query.get(projectId, {useMasterKey: true, success: fun...}}

這就是奇怪的是,錯誤對象爲空。應該有消息unauthorized

編輯:試試這個語法您的錯誤功能:error: function(model, error) { console.log(error); }

+0

我認爲這將有事情做'Parse.Cloud.useMasterKey()'過,但沒有運氣。仍然失敗,錯誤對象仍未定義。 –

+0

如果您使用此語法,您會得到錯誤對象嗎? 'error:function(model,error){console.log(error); }' –

+0

我編輯了我的答案,這樣做給了我一個「無法訪問Parse API」的錯誤,我修復了這個錯誤,現在我遇到了新問題。 –

相關問題