3
votes

I used promise all function for running multiple promises. I'm getting error Uncaught (in promise) reject, but here I've used the catch block. I don't know how this it throw the error.

function fetch(data) {
  new Promise(function(resolve,reject) {
    data ? reject('reject') : resolve('resolve')
  })
}

Promise.all([fetch(), fetch('sssssssss')])
 .then(function(data) {
    console.log('all finished',data)
  })
 .catch(function(error) {
   alert('ssssssssssssss')
 })

fetch()
1
your fetch function doesn't return anything - try return new Promise....... if you want to return the promise - Jaromanda X

1 Answers

3
votes

See below code. hope it will solve your problem.

function fetch(data) {
  return new Promise(function(resolve,reject) {
    data ? reject('reject') : resolve('resolve')
  })
}

Promise.all([fetch(), fetch('sssssssss')])
 .then(function(data) {
    console.log('all finished',data)
  })
 .catch(function(error) {
   alert('ssssssssssssss')
 })

fetch()