Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142239

How to avoid propagation when chaining Promise with Non-Promise calls

$
0
0

I want the following code not to call OK logic, nor reject the promise. Note, I've a mixture of promise and non-promise calls (which somehow still managed to stay thenable after returning a string from its non-promise step), I just want the promise to stay at pending status if p1 resolves to non-OK value.

const p1 = new Promise((resolve, reject) => {
    resolve("NOT_OK_BUT_NOT_A_CATCH_NEITHER");
});

p1.then(result => {
    if (result !== "OK") {
        return "How do I avoid calling OK logic w/out rejecting?";
    }
    else {
        return Promise.resolve("OK");
    }
}).then(result => {
    console.error("OK logic...");
});

Viewing all articles
Browse latest Browse all 142239

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>