It’s unclear to me when it’s best to and shouldn’t return a HTTP 412: Precondition Failed, error for an online service? I’m considering of utilizing it when validating information. For instance, if a consumer POST’s XML information and that information is lacking a required information factor, then responding with a 412 and an outline of the error.
Does that align with the spirit of responding with an HTTP 412, or ought to one thing else be used (e.g. one other http error code or net software exception)?
In the event you take a look at RFC 2616 you may see a variety of request headers that can be utilized to use circumstances to a request:
If-Match If-Modified-Since If-None-Match If-Vary If-Unmodified-Since
These headers include ‘preconditions’, permitting the consumer to inform the server to solely full the request if sure circumstances are met. For instance, you employ a
PUT request to replace the state of a useful resource, however you solely need the
PUT to be actioned if the useful resource has not been modified by another person since your most up-to-date
The response standing code
412 (Precondition Failed) is usually used when these preconditions fail.
Your instance feels like an invalid request (i.e. the consumer has submitted information that’s invalid due to lacking values). A standing code of
400 (Unhealthy Request) is extra acceptable right here IMO.