How can I get the result of reject?

could anybody tell me how I can get the result of reject ? I tried modify the line"let responseFromServer = true;" to"let responseFromServer = false;" , but it doesn’t work, I’m really confused about this as I haven’t understood “Promise” so much, thanks !

  **Your code so far**

const makeServerRequest = new Promise((resolve, reject) => {
// responseFromServer is set to true to represent a successful response from a server
let responseFromServer = true;
  
if(responseFromServer) {
  resolve("We got the data");
} else {  
  reject("Data not received");
}
});

makeServerRequest.then(result => {
console.log(result)
})
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36

Challenge: Handle a Fulfilled Promise with then

Link to the challenge:

The reject “throws” and error, so you have to “catch” it. Using the then format, you would do that with a catch method:

makeServerRequest.then(result => {
  console.log(result)
}).catch(err => {
  console.log(err)
})
1 Like

Thanks, I got it! :grinning: :grinning: :grinning: