Tell us what’s happening:
Hi someone could clarify this for me please?
I read in the lesson " It is executed immediately after a promise’s reject method is called" and you can see my code calling for ‘catch’ just after ‘reject’. The test is passed but in the solution provided it is called after the ‘then’ method. Any idea?
Thank you
p.s this applies to how the then syntax is explained too
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)})
}
});
makeServerRequest.then(result => {
console.log(result);
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.
Challenge: Handle a Rejected Promise with catch
Link to the challenge: