美文网首页
promise reject

promise reject

作者: 空天啸鹤 | 来源:发表于2020-03-19 18:19 被阅读0次

    1.promise((resolve, reject) =>{}), 逻辑中必须调用resolve 或 reject来返回数据或继续执行外层逻辑,否则无法执行;

    2.使用async await 组合是,需要做catch,否则出现uncatch err 导致后续代码无法执行;

    // postSignInAPI({ id, type })
          //   .then(res => {
          //     console.log('-signin-ok:', type, id, res)
          //   })
          //   .catch(res => {
          //     console.log('-signin-errr:', type, id, res)
          //   })
          console.log('-signin-2-', type, id)
          const res = await postSignInAPI({ id, type }).catch(e => {
            console.log('-signin-errr:', type, id, e)
          })
          console.log('-signin--', type, id, res)
          if (res) {
          }
    

    3.return new promise((resolve, reject) =>{}).catch(e =>{}), 逻辑中reject被catch住的话,异常将无法抛出,改进如下:

     if (config && config.dontCatchErr) {
        return new Promise(reqFun)
      }
      return new Promise(reqFun).catch(e => {
        console.error('catch: ', e)
      })
    

    相关文章

      网友评论

          本文标题:promise reject

          本文链接:https://www.haomeiwen.com/subject/beolyhtx.html