Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

javascript - Unhandled rejection reasons (should be empty)

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();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Based on this confusing discussion it's a false positive.

To silence the logging you can do this:

Q.stopUnhandledRejectionTracking();

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...