Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be Consistent - response #58

Open
Nizar7zak opened this issue Apr 14, 2022 · 0 comments
Open

Be Consistent - response #58

Nizar7zak opened this issue Apr 14, 2022 · 0 comments

Comments

@Nizar7zak
Copy link

Nizar7zak commented Apr 14, 2022

.then(({ rows }) => res.status(201).json(rows))

in responses you send the 
1.   .json({ status: 201, message: 'Product Added', product: rows[0] }))
2.  .json({ status: 200, message: 'Product Deleted' }))
3. .json(rows))
4. .json({ status: 200, message: 'Product Updated', product: rows[0] }))

should be consistent when we send a response for client side, moreover why you send a status in the body of response if we have it in status > res.status(200)

here is a question for you all, what if the rowCount equal 0, I mean what if there is no products in data base? In the same context we handle the 4xx errors in catch of promise, not the internal server error, we handle this error in Express error middleware like this ;

const serverError = (err, req, res, next) => {
  return res.status(500).json({ message: 'internal server error 500' });
};

you did a good work, all issues just to be a professional developers ;)

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

No branches or pull requests

1 participant