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

API server returns incorrect HTTP status code #326

Open
javibookline opened this issue May 31, 2024 · 1 comment
Open

API server returns incorrect HTTP status code #326

javibookline opened this issue May 31, 2024 · 1 comment
Assignees

Comments

@javibookline
Copy link

if (err.code === 'ER_DUP_ENTRY') {
logger.info(err, 'duplicate entry on insert');
return res.status(422).json({msg: err.message});

When trying to create a resource that already exists, the code returned is 422 (unprocessable resource) when it should return a 409 (conflict).

@javibookline
Copy link
Author

The reason it is useful to return the proper code is that it enables better handling of the response - trying to insert something unprocessable should maybe trigger a manual review (i.e. when inserting a carrier bound to an account, the account does not exist) whereas inserting a duplicate entry does not require that, and automated flows benefit from this distinction.

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

2 participants