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 Node.js Basics 2017 Handling Errors in Node Handling Status Code Errors

Richard Preske
PLUS
Richard Preske
Courses Plus Student 4,356 Points

Trouble figuring out my bracket to end the "else" statement

https://w.trhou.se/xg3qafhyar

Having trouble with the bracket ending the "else" statement.

Steven Parker
Steven Parker
231,268 Points

The snapshot seems to run as-is. What kind of trouble are you having with it?

Richard Preske
Richard Preske
Courses Plus Student 4,356 Points

treehouse:~/workspace$ node chalkers
module.js:550
throw err;
^

Error: Cannot find module '/home/treehouse/workspace/chalkers'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3

The above is what I am getting when running with correct username or wrong username. Should show statement with error code when wrong username inputted.

1 Answer

Steven Parker
Steven Parker
231,268 Points

The first argument to "node" must be the name of the script. Try running it like this:

node app.js chalkers

Richard Preske
Richard Preske
Courses Plus Student 4,356 Points

Oops forgot the app.js. But here is what I get with node app.js chalkers-not

    const message = `There was an error for getting the profile for ${username} (${http.STATUS_CODE[response.sta                                            

tusCode]})`;
^

TypeError: Cannot read property '404' of undefined
at ClientRequest.https.get.response (/home/treehouse/workspace/app.js:33:104)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:552:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
at TLSSocket.socketOnData (_http_client.js:454:20)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
treehouse:~/workspace$ ^C

Steven Parker
Steven Parker
231,268 Points

The code isn't quite complete, it's still missing the definition of "http" and the "printError" function. These are covered in the latter part of the video and the "Teacher's Notes" on the course page.

Then, the correct property name for looking up errors is "STATUS_CODES" (plural) instead of "STATUS_CODE" (singular).