craftql
craftql copied to clipboard
Insert entries with failed validation is returning status 500 as http code
When we are using the mutation for insert an entry to the craft database, everything is ok when the fields are right.
But if some of the fields failed in validation, instead to return 400 that is the most appropriated code for validation errors. It is returning 500.
I'm not sure I agree. 400 would be a not found or not authorized class error. 500 indicates that something went wrong.
What status code would you expect and do you have any examples of other services that do something similarly?
Hey Mark. I think it is wrong. The 500 indicates some error at the server (internal server error), something that couldn't be processed and the webserver shows this error. It is related to not treated situation, some programming error, etc. A validation error message is not a server/webserver error response. It is a proper response that the data cannot be saved at database because not respect the format, etc. The 400 and related 4xx is the http code specific for this cases. It is a bad request, and it was identified and the response indicates what is wrong for the user.
@markhuot kind of agree with Rodrigo's point here, Mark. I've been surprised also by 500s coming from CraftQL's disagreement about queries. And these are not 'server' failures -- they are information-not-acceptable-to-application problems, suspect you'd agree if put that way.
Looking over the codes in usage, how about 422?
According to Wikpedia's summaries, this means '422 Unprocessable Entity (WebDAV; RFC 4918) The request was well-formed but was unable to be followed due to semantic errors.[17]'
...and the other advantage of 422 is probably that it's seldom seen, thus a nice flag that can be doc'd, to let know that something pretty hidden, the CraftQL query, is the root of a problem...
422 is what Laravel uses for validation errors, I think it's a good choice
Surprised to reference this and find it closed -- @markhuot , any reason not to return informative codes, either case?