Search code examples
javascriptecmascript-6promisees6-promise

Javascript promise: catch flow


In the following code, I want to be able to exit app when foo fails, but not when goo fails. My problem is that when goo rejects, it's getting caught in foo's catch. Is there a promise best practice solution to this issue?

foo().then(() => {
    return goo.catch(() => {
        //do something
        //reject but don't exit app
    })
})
.catch(() => {
    //exit app
    //reject
})

Solution

  • I think this does the trick:

    foo()
    .catch(() => {
        //exit app
        //reject
    })
    .then(() => {
        return goo.catch(() => {
            //do something
            //reject
        })
    })