简体   繁体   中英

Uncaught promise with babel-polyfill

There is the following simple code:

  function getPromise() {
    return new Promise((resolve, reject) => {
      reject();
    })
  }

  getPromise().then(() => {});

As you can see I just return promise which are always reject, but I don't want to catch it. So, I see in console error:

Uncaught (in promise)

I don't want to catch it, but I don't want to see this error. What should I do? I use babel-polyfill.

You are rejecting a promise and not catching it. Simply catch the error and do nothing with it. That is the only way to handle rejected promises in vanilla JS until the finally method makes it into the spec, probably for ES2018 .

getPromise().then(() => {}).catch(() => {});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM