1
votes

I have something of a simple usecase: User has a set of Privileges; when I create the User resource I do not want to also create Privileges; so, if a new User with new Privileges comes from the client, I want to respond with something along the lines of:

I cannot create the User Resource because the Privileges it contains do not exist.

At this point, the client can do a Create on the Privilege first and then add them to the User and create that.

The question is what Error status code to use for the HTTP response:

  • 412 - Precondition Failed
  • 424 - Failed Dependency

I also considered (but do not seem to fit the usecase):

  • 400 - Bad Request
  • 422 - Unprocessable Entity
2

2 Answers

0
votes

422 and 424 have a specific WebDAV meaning. So they don't apply.

412 is about a precodition the client requested. So it doesn't apply, too.

Maybe 409 Conflict could be used.

Edit: 409 Conflict is about the client asking the server to put the server's resources into an impossible or inconsistent state. So I think it applies to your sitation. As long as the referenced Privileges don't exist on the client, a User referencing them can't be created.

Edit: Take a look at http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

1
votes

409 sounds good; the client can do a separate request to resolve the conflict, in which case the operation would have succeeded. (You could use a Link with a custom link relation to identify the resource the operation was in conflict with)