JavaScript Node.js Basics 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

Ga In Shin
Ga In Shin
9,929 Points

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('', (res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);

  res.on('data', (d) => {

}).on('error', (e) => {
Chris Jones
Chris Jones
Java Web Development Techdegree Graduate 23,745 Points

Are you getting any output when the program runs? Or is the error handler just not being executed?

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