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 REST API With Express Completing and Testing the API Next Steps

I found that if you replace any char in the qID or aID with another char, the entire server breaks. How to handle that?

in Postman or Browser if you send a Get request to a specific question with qID and you replace any char in the question id with any other char, the server breaks. So, Im sure we can handle that but what is the proper way to do so?

Can you post your code?

2 Answers

you're not defining, setting status code, and passing the error correctly Check your routes.js file

on lines 10-14 ('qID' param middleware):

if (!question) {
    error = new Error("Not Found");
    res.status = 404;
    return next(err);
}

should be:

if (!question) {
    let err = new Error("Not Found");
    err.status = 404;
    return next(err);
}

same goes for 'aID' param middleware in line on lines 24-28.

this is the link to repo https://github.com/jay51/qa-express-api/tree/version3 and checkout branch: version3