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 Build a Simple Dynamic Site with Node.js Handling Routes in Node.js Populating User Information

Incorrect error message

How come the error.message states (Found) on a user that could not be found?

e.g.

There was an error getting the profile for chalkers123123. (Found)

2 Answers

Steven Parker
Steven Parker
231,236 Points

The server operation has apparently changed since that course was created. Now, instead of returning a "not found" error, the server redirects you to your home page.

You may want to report this to Support, they can add something to the "Teacher's Notes" and it should get you a "special Exterminator badge". :beetle:

Historical Note: The video uses "chalers123" but then some joker created an account with that name. :laughing:

Thanks for the explanation Steven!

To remedy, I've added an extra check to the profiles.js. This checks if the Status Code is a redirect (302) and that the location of the redirect is https://teamtreehouse.com/home.

Probably not the most ideal or elegant of solutions but it seems to do the trick, and it got me looking more into status codes and all the different keys you can access from response.headers !

    // Connect to the API URL (https://teamtreehouse.com/profiles/username.json)
    var request = https.get("https://teamtreehouse.com/profiles/" + username + ".json", function(response) {
        var body = "";

    // Added this addition check:
        if (response.statusCode === 302 && response.headers.location === "https://teamtreehouse.com/home") {
            request.abort();
            profileEmitter.emit("error", new Error("There was an error getting the profile for " + username + ". (Not Found)"));
            return;
        } else 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] + ")"));
        }

I did notice that there was a chalkers123 account which was the error example Andrew gave in the videos! 😂

Steven Parker
Steven Parker
231,236 Points

Oh that's right! I updated my note about it.

And checking for a redirect status is a perfect solution given the way the server operates now. I don't think it's even necessary to check the location.