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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Aakash Srivastava](https://secure.gravatar.com/avatar/801c5dda7c90ff2cd36be568bcc54785?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Aakash Srivastava
5,415 PointsError handling in Node.js
I have a question which took my whole day but still scratching my head .
I am wondering , why Errors are being handled differently in this course ?
When i saw profile.js file , errors have been handled differently here. Why?
I remember , Chalkley told us about the types of Errors in Node.basics course and that were :
- Asynchronous errors
- Error from developers perspective
- Parsing errors
- status code errors
Now , all the errors have been handled in this course too . The only difference is Asynchronous Error is handled this time on response object inspite of request object which happens in last course . Why is this so? I have really given a lot of time understanding this , any help would be much appreciated .
Please explain in detail . Jennifer Nordell
1 Answer
![Bob Swaney](https://uploads.teamtreehouse.com/production/profile-photos/9907902/micro_this_is_me.jpg)
Bob Swaney
13,010 PointsHello, I'm not 100% sure, as I am in the process of taking this course as well...but after doing some digging on the nodejs.org website and looking through the code that we are working on up to this point, I have deduced the following... At one point in this section, we copy a snippet of code from 'example_profile.js' into 'router.js' ... require('./profile.js') ... we haven't really gone through this massive file, we just include it...It handles a lot of things that we didn't really touch on..and if you notice, through this very lesson exercise, we are getting back badge counts from the Treehouse API without having to use the ('https') or ('http') modules and using the .get() method on either like we did the Node.js basics...so how are we connecting with it? Through requiring the profile.js file... So on to the error handling...if you notice when we put in the wrong username information, we get back an error without a stack trace, that seems very similar to the 'brushed up' code that we did in Node.js Basics course...it is simplified and also shows the 'http status code' not by number (404), but by (Not Found)...this snippet of code is also found within the 'profile.js' file we require in 'router.js'..
from profile.js --
if (response.statusCode !== 200) {
request.abort();
//Status Code Error
profileEmitter.emit("error", new Error("There was an error getting the profile for " + username + ". (" + http.STATUS_CODES[response.statusCode] + ")"));
}
So, it looks like we are tackling harder issues for the moment, with being able to run and connect to an http server in general, and are less worried about the various different way to handle errors for the moment. I hope this helps and makes sense.