I am currently writing a backend JSON API built with nodejs & express but this question can probably apply to any backend API’s
What is the standard way of handling model validation errors when a bad or incomplete request is sent to the server and what response should be given to the client?
Currently, my application is sending status codes if something was to go wrong. Is this enough?
Edit:
I have fully functioning validations on the client side app, so I am not overly fussed, but it would be nice to have all the angles covered.
You should perform server-side validations regardless of whether you do it client-side too.
Returning any of the 4xx, 5xx errors will do, choose the ones that describe your conditions.
It is sometimes useful in these cases to pass
{wait: true}in the options ofsaveorcreatein order to wait for the server response before saving/adding your models.