JavaScript Node.js Basics Handling Errors in Node Handling Errors in Node

Graeme Oxley
Graeme Oxley
8,918 Points

Quiz issue: Can't see what I am doing wrong

I have looked back to the previous video several times and my code is exactly as he did it, though I keep getting an error saying that I did not call the 'console.error', though I clearly did.

I am at a loss for what I am doing wrong, and the video has no more clues to give.

app.js
const https = require("https");

const request = https.get("https://teamtreehouse.com/chalkers.json", response => {
  console.log(response.statusCode);
});
request.on('error', error => console.error('Problem with request: ${error.message}'));

3 Answers

Adam Pengh
Adam Pengh
29,686 Points

I got this to work

const https = require("https");

const request = https.get("https://teamtreehouse.com/chalkers.json", response => {
  console.log(response.statusCode);
});

request.on('error', (error) => {
  console.error(error.message);
});
Graeme Oxley
Graeme Oxley
8,918 Points

Choosing this one because it seemed to be closer to what I was expected to do from the beginning. Part of me is simply confused because I am not sure how I was expected to arrive at that answer to begin with. I only got as far as I did after a good amount of trial and error with no feedback from the quiz to help me understand what is wrong.

Thanks for the help.

Romain Gaget
Romain Gaget
24,449 Points

you've used single quote in your error message where you should use back-tick (`) instead in order to use template literal syntax request.on('error', error => console.error(Problem with request: ${error.message}`));

Graeme Oxley
Graeme Oxley
8,918 Points

Thank you for the alternative answer. Obviously at this stage I haven't even heard of the use of the back-tick for any functional purpose, and upon looking back I see that I did confuse the video's use of the back-tick for a single quotation.

It would have been helpful if Chalkers had mentioned the back-tick use since I don't imagine it is something that a novice would be used to seeing.

Steven Parker
Steven Parker
203,733 Points

Romain is correct about needing accents ("back-ticks") to define template literals, but that's not what you need here to pass the challenge.

When the instructions say "print out the error message", they literally mean just the message property of the error object itself. You won't need any additional strings this time.

Graeme Oxley
Graeme Oxley
8,918 Points

Thank you for the help, though admittedly your 2nd paragraph didn't help me to understand the problem since it was simply an explanation of the answer which I didn't really understand until I saw the code that Adam Pengh posted (easier to learn from code than text, for me at least).

Steven Parker
Steven Parker
203,733 Points

I was afraid I was being a bit too explicit. When I said "the message property of the error object itself" with "no additional strings" I expected it would translate directly into "error.message", which was what you used to pass the challenge.