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 trialJavier MARQUEZ
11,877 PointsI 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.
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
11,877 PointsThanks 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
Full Stack JavaScript Techdegree Graduate 29,228 PointsHi, 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
Full Stack JavaScript Techdegree Graduate 29,228 PointsOoooops ! 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
857 PointsJust 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
11,877 PointsThanks 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));
Ella Ruokokoski
20,881 PointsI think you have forgotten to add curly braces around your callback function.
edit. oh Raphael was a tad faster :)
Raphaël Seguin
Full Stack JavaScript Techdegree Graduate 29,228 PointsAlright ! Upvote the answer if you like it :) ! Cheers.