According to some questions and answers, an appropriate code for cases where a username, for example, is too short, does not meet given requirements, etc., is 422, even though a lot of recommending 400 as well.
The status code advised when an e-mail address is in use is 409, once again according to other posts.
Which one should I return if the entered username is too long and the e-mail address is not available? Aren't both technically correct? Which one should be the dominant one?
CodePudding user response:
HTTP status codes are of the [transfer of documents over a network] domain. They are there to communicate to general purpose HTTP components the nature of the provided response - is the payload a representation of a requested resource, or a representation of an error? what semantics apply to the HTTP headers? should this response invalidate previously cached responses? and so on.
It may help to think about it in the context of the web, where information for the human user is in the HTML document, but the status code and headers are interpreted by the browser.
400, 403, 409, 422 are all reasonable choices. Since "fixing the conflict and retrying" isn't going to succeed with a payload that doesn't satisfy the constraints of the schema that the server is expecting, I'd steer clear of 409. Similarly, trying with a different set of credentials isn't going to help, so 403 isn't a perfect fit either.
I'd probably use 422, because it directs a human being's attention to the request payload.