Hey all!
Here’s some quick help for the X-Press Publishing capstone project.
I kept running into the following error during my NPM tests: “should return a 404 status code for invalid issue IDs”.
Reviewing the solution code, I realized that in issues.js I had the following code:
issuesRouter.param('issueId', (req, res, next, issueId) => {
const sql = 'SELECT * FROM Issue WHERE Issue.id = $issueId';
const values = {
$issueId: issueId
};
db.get(sql, values, (err, issue) => {
if (err) {
next(err);
} else if (issue) {
next();
} else {
res.sendStatus(400);
}
});
});
Take a look at the final else block. I sent a 400 status code! Silly me. It should have be written:
issuesRouter.param('issueId', (req, res, next, issueId) => {
const sql = 'SELECT * FROM Issue WHERE Issue.id = $issueId';
const values = {
$issueId: issueId
};
db.get(sql, values, (err, issue) => {
if (err) {
next(err);
} else if (issue) {
next();
} else {
res.sendStatus(404);
}
});
});
Hope that helps!