Suppose we have a gRPC DB-backed application with some resource X
like this, for example in Go:
type X struct {
id string
name string
version string
}
And for some reason the application does not permit updates unless version = "2"
.
If a client tries to make a request to update the name of an existing resource whose version = "1"
, like this:
// This exists in the DB.
x := X{
id: "xyz",
version: "1",
name: "some name",
}
UpdateX(
X{
id: "xyz",
name: "some other name",
},
)
what gRPC error code should be returned?
Referring to the codes here: https://grpc.github.io/grpc/core/md_doc_statuscodes.html, I can see arguments for both INVALID_ARGUMENT and FAILED_PRECONDITION.
INVALID_ARGUMENT:
FAILED_PRECONDITION:
Based on your description, you should probably use FAILED_PRECONDITION. Like mentioned in https://grpc.github.io/grpc/core/md_doc_statuscodes.html: INVALID_ARGUMENT indicates arguments that are problematic. But in your case the arguments is correct, but the system does not allow update, thus I think FAILED_PRECONDITION is a better fit.