Skip to content

Node eval#179

Open
j-emitch wants to merge 20 commits intoprojectshft:masterfrom
j-emitch:master
Open

Node eval#179
j-emitch wants to merge 20 commits intoprojectshft:masterfrom
j-emitch:master

Conversation

@j-emitch
Copy link

@j-emitch j-emitch commented May 6, 2025

No description provided.

@@ -1,11 +1,257 @@
swagger: '2.0'
swagger: "2.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

description: "Unauthorized"
schema:
$ref: "#/definitions/Error"
post:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be put method

Comment on lines +40 to +42
if (err) return res.status(401).json({ error: 'Unauthorized' });
req.user = user;
next();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beware your code alignment

const { id } = req.body;
const userCart = users.find((u) => u.login.username === req.user.username).cart;
if (!userCart) {
return res.status(401).json({ error: "Unauthorized" });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is 404, not 401.
401 Unauthorized is a bit misleading if the cart doesn’t exist — if users.find() returns undefined, that’s more of a 404 Not Found or 403 Forbidden.


app.post('/me/cart', authenticateToken, (req, res) => {
const { id } = req.body;
const userCart = users.find((u) => u.login.username === req.user.username).cart;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user isn’t found, your code will throw an error on .cart access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants