Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics 2017 Handling Errors in Node Handling the Error Event in Node

can anyone tell me what is wrong with this error handler?

request.on('error', error => console.error(Problem with request: ${error.message}));

the back ticks are there they just dont want to copy for some reason

4 Answers

hey Ellis, I had the same problem, and found the solution in the node.js document.

You have to put your error handler on the outside of the whole get() method as such:

https.get('https://encrypted.google.com/', (res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);

  res.on('data', (d) => {
    process.stdout.write(d);
  });

}).on('error', (e) => {
  console.error(e);
});

i am getting an out put yes:

but it s the same message i would be getting without the error handler

i actually went into the next workspace where the teacher had left his finished code, i copy/pasted and over wrote my own code, was pretty much identical anyway, and still........the error handlers do not seem to work