未处理的拒绝原因(应为空) [英] Unhandled rejection reasons (should be empty)

查看:125
本文介绍了未处理的拒绝原因(应为空)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Q进入promises模式,我不断收到警告[Q]未处理的拒绝原因(应该是空的)在控制台中。我做错了什么?

I'm getting into promises pattern with Q and I keep getting warning "[Q] Unhandled rejection reasons (should be empty)" in console. What em I doing wrong?

http:// jsfiddle .net / FpyDr / 1 /

function load(url) {
    var deferred = Q.defer();

    $.ajax({
        type: "GET",
        processData: false,
        dataType: "html",
        url: url,
        cache: false
    }).done(function (response, status, xhr) {

        deferred.reject(new Error("test error"));

        return;
    }).fail(function (xhr, status, error) {

        deferred.reject(new Error("ajax failed"));

        return;
    });

    return deferred.promise;
}

load("http://fiddle.jshell.net")
    .then(function (result) {
        console.log("got result", typeof(result));
    })
    .catch(function (error) {
        console.log("got error", error);
        return true;
    })
    .done();


推荐答案

基于这个令人困惑的讨论这是误报。

要使记录静音,您可以这样做:

To silence the logging you can do this:

Q.stopUnhandledRejectionTracking();

如果你没有捕获拒绝,它会抛出错误,所以你仍然会看到它在添加上面的代码后在控制台中。 JSFiddle: http://jsfiddle.net/homeyer/FpyDr/22/

If you didn't capture the rejection it would throw the error, so you'll still see it in the console after adding the code above. JSFiddle: http://jsfiddle.net/homeyer/FpyDr/22/

这篇关于未处理的拒绝原因(应为空)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆