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 trialJennifer Nordell
Treehouse TeacherHandling 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
15,000 PointsHey 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!
Elijah Gartin
13,182 PointsThank 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.
Kiril Kostov
827 PointsYes, 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.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherI'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
15,000 PointsDaniel Gauthier
15,000 PointsThat 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
Treehouse TeacherJennifer Nordell
Treehouse TeacherBTW 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...