Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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