JavaScript Node.js Basics Handling Errors in Node Handling Errors in Node

James Barrett
James Barrett
13,253 Points

'Finally, in the error callback, use the error method on the console to print out the error message.'

Hi guys,

Why is this challenge not passing? Am I having silly moment?

Thanks, James.

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

3 Answers

Steven Parker
Steven Parker
203,716 Points

It's the function definition.

When I tried your code, I got: "Bummer! Cannot read property 'hasCallExpression' of undefined".

I'd guess the "undefined" has something to do with either this or arguments inside the checking code, neither of which get defined when you use the arrow form of function definition.

:point_right: Just use a conventional anonymous function definition to avoid this issue.

James Barrett
James Barrett
13,253 Points

Thanks, this seemed to solve it. Perhaps this is something that should be flagged to Andrew Chalkley ?

John Hirleman
John Hirleman
11,376 Points
```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));
blake guyan
blake guyan
8,297 Points

i just put the code you pasted in here into the challenge and it worked?

James Barrett
James Barrett
13,253 Points

It works up until challenge 3.