2014-12-02 52 views
0

我目前正在按照教程https://parse.com/tutorials/integrating-with-third-party-services解析整合第三方服務

在模塊中,sendEmail功能設置像這樣:

sendEmail: function(params, options) { 
    return Parse.Cloud.httpRequest({ 
    method: "POST", 
    url: "https://api:" + key + "@" + url + "/" + domain + "/messages", 
    body: params, 
    }).then(function(httpResponse) { 
    if (options && options.success) { 
     options.success(httpResponse); 
    } 
    }, function(httpResponse) { 
    if (options && options.error) { 
     options.error(httpResponse); 
    } 
    }); 
} 

每當我跑,捲曲的功能,並試圖安慰.log選項散列,選項散列總是未定義的。

的後果是,我不能讓HttpResponse對象回調

Parse.Cloud.define("sendEmailToUser", function(request, response) { 
    client.sendEmail({ 
    to: "[email protected]", 
    from: "[email protected]", 
    subject: "Hello from Parse!", 
    text: "Using Parse and My Mail Module is great!" 
    }).then(function(httpResponse) { 
    response.success("Email sent!"); 
    }, function(httpResponse) { 
    console.error(httpResponse); 
    response.error("Uh oh, something went wrong"); 
    }); 
}); 

我怎樣才能在上面的回調HttpResponse對象?

回答

0

你只需要返回你得到的結果,那麼它將繼續傳遞給下一個成功/錯誤處理程序

sendEmail: function(params, options) { 
    return Parse.Cloud.httpRequest({ 
    ... 
    }).then(function(httpResponse) { 
    if (options && options.success) { 
     options.success(httpResponse); 
    } 
    return httpResponse 
    }, function(httpResponse) { 
    if (options && options.error) { 
     options.error(httpResponse); 
    } 
    return httpResponse 
    }); 
}