Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-未破坏的承诺被拒绝,即使它已经被拒绝_Javascript_Parse Platform_Promise - Fatal编程技术网

Javascript-未破坏的承诺被拒绝,即使它已经被拒绝

Javascript-未破坏的承诺被拒绝,即使它已经被拒绝,javascript,parse-platform,promise,Javascript,Parse Platform,Promise,我正在运行这个Parse.com云代码作业。它查询我的一个类并获取url,然后我读取这些url,它们是xml文件,我从中获取一些数据并保存下来进行解析。从代码中可以看出 这是密码 完整代码在这里 当我运行这个云代码作业时。在控制台中。我看到了这个消息 失败原因:未捕获承诺被拒绝,即使它已被拒绝。 这是因为一些URL无效,然后代码中断 基本上,我需要一种方法来处理它时,一个网址是不工作的,没有代码停止!!并继续使用其他URL 这个问题发生在第77-83行之间,在该行中传递url变量,因此我需要它忽

我正在运行这个Parse.com云代码作业。它查询我的一个类并获取url,然后我读取这些url,它们是xml文件,我从中获取一些数据并保存下来进行解析。从代码中可以看出

这是密码

完整代码在这里

当我运行这个云代码作业时。在控制台中。我看到了这个消息

失败原因:未捕获承诺被拒绝,即使它已被拒绝。

这是因为一些URL无效,然后代码中断

基本上,我需要一种方法来处理它时,一个网址是不工作的,没有代码停止!!并继续使用其他URL

这个问题发生在第77-83行之间,在该行中传递url变量,因此我需要它忽略错误的url,然后继续处理其余的url


提前感谢您的帮助。

这是一条奇怪的错误消息

据我所知

在第89行和第90行之间插入:

    }, function() {
        return Parse.Promise.as();//return resolved promise to keep the promise chain going.
给予:

return Parse.Cloud.httpRequest({
    url: url,
    //data: ... //some properties of menuItem?
}).then(function(httpResponse) {
    return readResponse_async(httpResponse.text).then(function(res) {
        if (res.menu.day.at(dayNumber).meal) {

            return saveMeals_async(res.menu.day.at(dayNumber).meal, school, diningHallNumber, menuLocation);
        } else {
            return Parse.Promise.as();//return resolved promise to keep the promise chain going.
        }
    }, function() {
        return Parse.Promise.as();//return resolved promise to keep the promise chain going.
    });
});
或者再低一行:

return Parse.Cloud.httpRequest({
    url: url,
    //data: ... //some properties of menuItem?
}).then(function(httpResponse) {
    return readResponse_async(httpResponse.text).then(function(res) {
        if (res.menu.day.at(dayNumber).meal) {

            return saveMeals_async(res.menu.day.at(dayNumber).meal, school, diningHallNumber, menuLocation);
        } else {
            return Parse.Promise.as();//return resolved promise to keep the promise chain going.
        }
    });
}, function() {
    return Parse.Promise.as();//return resolved promise to keep the promise chain going.
});
编辑

由于这两种方法都未能处理错误,您可以尝试这样做,这很混乱,但如果我怀疑Parse的承诺不是“抛出安全的”,则可以容忍:


您的promise用法看起来是正确的。@BenjaminGruenbaum您认为问题可能在其他地方吗?我看不出它是怎么回事?您能给我们展示一下SaveFeeds\u async吗?@BenjaminGruenbaum这里是浅读的完整代码-您似乎非常了解promise,并且正确地使用promise并发模式。我没有看到“明显”的缺陷,我唯一的建议是使用调试器一次一项地检查代码-这可能是一个解析问题。我将代码与您的编辑一起发布在这里,只是为了确保我的操作正确。但这仍然是一个错误。我可能是一个错误。试着拆下这两条线,然后在第90行和第91行之间重新插入。这将处理一个
Parse.Cloud.httpRequest()
错误。如果这仍然不起作用,那么您必须怀疑
Parse.Cloud.httpRequest()
是否成功,并且错误是从成功处理程序中抛出的。您是否可以添加它?我很难看到您希望我添加它的位置。它仍然会停在断开的url处。如果有帮助,这里是断开的url,问题是,服务器在错误条件下返回“成功”的HTTP响应,readResponse\u async()尝试将其解析为真正成功;Parse的承诺似乎不是“安全的”。解决方案在于(a)服务器端-返回真实错误(400系列);(b) 使
readResponse\u async()
容忍错误响应;(c) 使te主例程能够容忍readResponse\u async缺乏容忍度。我将根据(c)进行另一次编辑。
return Parse.Cloud.httpRequest({
    url: url,
    //data: ... //some properties of menuItem?
}).then(function(httpResponse) {
    try {
        return readResponse_async(httpResponse.text).then(function(res) {
            if (res.menu.day.at(dayNumber).meal) {
                return saveMeals_async(res.menu.day.at(dayNumber).meal, school, diningHallNumber, menuLocation);
            } else {
                throw new Error();
            }
        });
    }
    catch(e) {
        return Parse.Promise.as();//return resolved promise to keep the promise chain going.
    }
}, function() {
    return Parse.Promise.as();//return resolved promise to keep the promise chain going.
});