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

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Handling errors in node.js ... challenge

Ok, guys I've looked through the current accepted answers out there regarding this section. But no matter what code I try myself or has been posted in the answers, I cannot get past this step. I'm currently stuck on step 2 and as I understand it there's now been some update to node which may be affecting this challenge. Can anyone either help me get through this or confirm or deny that this is the case? Thank you in advance.

Ooops! Here's the challenge: https://teamtreehouse.com/library/nodejs-basics/building-a-command-line-application/handling-errors-in-node-2

3 Answers

Daniel Gauthier
Daniel Gauthier
15,000 Points

Hey Jennifer,

The code it's looking for is:

var http = require("http");

var request = http.get("http://teamtreehouse.com/chalkers.json", function(response){
  console.log(response.statusCode);
});

request.on('error', function(error){});

Hope this helps get you through!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I'd like to point out that I'm an idiot. I've had my fair share of best answers, so I'm just sitting here shaking my head. I wrote this:

request.on("error', function(error) {});

A note to anyone else who gets stuck. Pick a style of quotes and stick with them! Sheesh...

Daniel Gauthier
Daniel Gauthier
15,000 Points

That is an awesome way to start the day though.

Not long ago I wrestled with one of the sites I was working on for an hour trying to figure out why certain elements weren't aligning properly when I finally realized I had been assigning floats to the wrong elements.

Good to see you made it through!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

BTW thank you very much, Daniel Gauthier. I was pulling my hair out over here. Luckily for me though, the last step didn't require any quote marks of any description! :) For whatever reason, I didn't associate the original error message I got from Treehouse with a syntax error...

Elijah Gartin
Elijah Gartin
13,182 Points

Thank you, both -- another thing I noticed is that the code challenge doesn't like arrow function notation.

In the tutorial it shows:

 request.on('error', error => console.error(`Problem with request: ${error.message}`));

In the challenge you have to write:

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

Thought I might also mention that JSLint seemed to dislike the use of single quotes.

Yes, I have pointed out this on previous exercises.

The tutor is using ES6 arrow functions to show you how to, and then exactly the same code won't work with weird errors... and without a warning to use vanilla JS.