I am using Ruby on Rails and I am trying to understand all the subtleties of HTTP codes to bring my app with standards, and I’m facing the following case.
Let’s say I have a database with two tables, Companies and Employees.
- If users try to delete a company with no employee, it is deleted and server sends code 200.
- If users try to delete a company with employees, it is not deleted and server sends a message (“There are employees linked to this company…”). In this case, what code does server have to send ? I was thinking of HTTP 4XX but in my opinion, it is not a client error.
Use the 409 Conflict error code. It indicates that the request could not be processed because of conflict in the request.
Once the employees are gone then the conflict is removed and the delete will work. You can think of it as a client error in the sense that it is a conflicted request from the client.