We have an integration with an external client that pushes data into our system through a REST API.
For validation issues related to the payload (data transfer objects), we return 422 Unprocessable Entity
if something is not accurate.
Now, when we have scenarios like adding a new user and the user exists on the database, we consider this as a validation error as well, and we don't allow the client to submit the user information because it was already persisted.
Is the 422
status code valid for this type of scenario where we want to avoid duplicate records?
CodePudding user response:
The status code I would use for this case is 409
. 409
is used in cases where the request body is valid, and it's otherwise a valid request, but the current state of the server prevents the request from being successful.
I wrote more about 409 here
CodePudding user response:
In my opinion 422 is definitely suitable for this scenario. As far as I have seen there is no status code that describes an invalid payload because it is a duplicate.
EDIT: I did not know about 409 but it seems more suitable.