-1

I have this code that returns a Promise as i see in the browser

    const data2 = fetchCurrentWeatherID({
    params: {id: data.id - 3204, appid: 'ebc8de08ce3579cf444b51c12772a8bc'},
  })

  console.log(data2)

The result in the browser is:

↓Promise {<pending>}
 →[[Prototype]]: Promise
  [[PromiseState]]: "rejected"
 →[[PromiseResult]]: Error: Request failed with status code 404 at createError (http://localhost:3000/vendors~main.8c0082efa14d3f9d53ec.hot-update.js:767:15) at settle (http://localhost:3000/vendors~main.8c0082efa14d3f9d53ec.hot-update.

in case the Promise is resolved the result is:

↓Promise {<pending>}
 →[[Prototype]]: Promise
  [[PromiseState]]: "fulfilled"
 →[[PromiseResult]]: Object

I would like to access the PromiseState and the PromiseResult! I have made this API call with React.js

konsbe
  • 1
  • 1

1 Answers1

0
const data2 = fetchCurrentWeatherID({
  params: {id: data.id - 3204, appid: 'ebc8de08ce3579cf444b51c12772a8bc'},
})

console.log(data2);
data2
  .then(result => console.log(result))  // the resolved data result
  .catch(err => console.log('something went wrong, error was', err)); // any errors
Christian Fritz
  • 20,641
  • 3
  • 42
  • 71
  • thanks! thats what ive done! fetchCurrentWeatherID({ params: {id: data.id - 3204, appid: 'ebc8de08ce3579cf444b51c12772a8bc'}, }).then(data2 => { console.log(data2.data.name) }) Is it possible to get the Promise results ? something like data2.PromiseState ? or something similar ? – konsbe Oct 16 '21 at 19:16