How to handle the if-else in promise then?

后端 未结 3 1720
旧时难觅i
旧时难觅i 2020-12-04 09:36

In some case, when I get a return value from a promise object, I need to start two different then() precesses depend on the value\'s condition, like:

         


        
3条回答
  •  不知归路
    2020-12-04 09:57

    This is how I did it in my fetch() I am not sure if this is the right way, but it works

     fetch().then(res => res.ok ? res : false).then(res => {
        if (res) {
            //res ok
        } else {
           //res not ok
        }
    
    });
    

提交回复
热议问题