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 Errors in Node

Javier MARQUEZ
Javier MARQUEZ
11,877 Points

I understand really well, but I am stuck in this challenge. Cannot read property 'hasCallExpression' of undefined

I tried to enter the exact same fat arrrow syntax, it should be working but it doesn't, I hate when this happens. I am out of ideas. Could anyone give me a hand.

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($error.message));

7 Answers

Javier MARQUEZ
Javier MARQUEZ
11,877 Points

Thanks a lot for your help, you are the best.

I finally got it, like this but actually outside the const request

request.on("error", (error) => {
    console.error(error.message)
  });
Raphaël Seguin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Raphaël Seguin
Full Stack JavaScript Techdegree Graduate 29,228 Points

Hi, maybe you could try to wrap "console.error(error.message)" in {} like this :

request.on("error", (error) => {
console.error(error.message)
});

I know it should work without it but I noticed strange behaviours like this before so ...

I hope it'll help.

Raphaël Seguin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Raphaël Seguin
Full Stack JavaScript Techdegree Graduate 29,228 Points

Ooooops ! You should put the statement in the callback, where the request lives:

const request = https.get("https://teamtreehouse.com/chalkers.json", response => {
    console.log(response.statusCode);
    request.on("error", (error) => {
    console.error(error.message)
  });
});
David Sims
David Sims
857 Points

Just from first glance I noticed you're using $error.message instead of error.message, so it's going to return undefined instead of the error.

Javier MARQUEZ
Javier MARQUEZ
11,877 Points

Thanks a lot, for some reason when asking the question I left it like that, however if I try the following it still doesn't work. The error I got is "Cannot read property 'hasCallExpression' of undefined"

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));

I think you have forgotten to add curly braces around your callback function.

edit. oh Raphael was a tad faster :)