Tell us what’s happening:
I’m finishing up the last two lessons of ES6, and don’t understand why my code is not behaving properly. All of the tests are passing, but the code does not actually log the error in my console once I catch it. I’ve tried moving it inside/outside the promise block, and the results never change.
I had the same experience with the previous challenge using then and results to post fulfilled promises.
Can someone help me figure out what’s missing?
Your code so far
const makeServerRequest = new Promise((resolve, reject) => {
// responseFromServer is set to false to represent an unsuccessful response from a server
let responseFromServer = false;
if(responseFromServer) {
resolve("We got the data");
} else {
reject("Data not received");
}
});
makeServerRequest.catch(error => {
console.log(error)
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
.
Challenge: Handle a Rejected Promise with catch
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/handle-a-rejected-promise-with-catch