gpt4 book ai didi

javascript - "Failed with: success/error was not called"试图在 Parse 中返回 httpResponse

转载 作者:行者123 更新时间:2023-11-30 17:18:42 24 4
gpt4 key购买 nike

请原谅我的 JS/Parse 新手。

我正在尝试使用 Promises 在常规函数中执行 Parse HTTP 请求(我尝试了非 promise 方式也无济于事)。对于我的生活,我无法获得 httpResponse.text。下面的代码导致“失败:未调用成功/错误”。

我相当确定这里有不止一个问题,也许我的方法有偏差。另请注意,console.log("FML") 打印在日志中,但 console.log("response is "+ httpResponse.text);不是。

function getTweets(team) {

// some code and the params for the http request

Parse.Cloud.httpRequest({
method: 'GET',
url: THE_URL,
headers: {
SOME_HEADER_PARAMS
},
body: {
}}).then(function(httpResponse) {
console.log("FML");
console.log("response is " + httpResponse.text);
return httpResponse.text;
}).then(function(error) {
return error;
});
};

另请注意:

  • console.log("FML") 打印在日志中,但 console.log("responseis "+ httpResponse.text); 不是。我的 HTTP 状态为 200,所以HTTP 请求似乎没问题

最佳答案

Parse 使用不同的语法来处理 promises 的错误。您的 promise 链应如下所示:

Parse.Cloud.httpRequest({...})
.then(function(httpResponse) {
console.log("FML");
console.log("response is " + httpResponse.text);
return httpResponse.text;
}, function(error) {
return error;
});

另请注意,大多数 promise 库不使用 then 来解决错误。他们通常使用 catch 进行错误处理。

关于javascript - "Failed with: success/error was not called"试图在 Parse 中返回 httpResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25577481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com