412 Client Error πŸ“‹

412 Precondition Failed: Conditional Request Rejected

Last updated: June 28, 2026 β€’ 6 min read

✦ The Golden Answer: The 412 Precondition Failed status code means the server does not meet one or more of the client's preconditions, as specified in conditional headers like If-Match, If-None-Match, If-Modified-Since, or If-Unmodified-Since. The server rejects the request because the preconditions evaluated to false. This is often used in optimistic locking: the client sends an If-Match header with an ETag, and the server checks if the current ETag matches β€” if not, it returns 412, indicating the resource has been modified elsewhere.

Common Precondition Headers

HeaderPurposeWhen 412 Occurs
If-MatchOnly perform the request if the resource's ETag matches the given value.ETag does not match (resource has changed).
If-None-MatchOnly perform the request if the resource's ETag does NOT match the given value.ETag matches (resource is unchanged, but client expected change).
If-Modified-SinceOnly perform the request if the resource has been modified since the given date.Resource has not been modified since that date.
If-Unmodified-SinceOnly perform the request if the resource has NOT been modified since the given date.Resource has been modified since that date.

Example: If-Match for Optimistic Locking

A client attempts to update a resource using an If-Match header with an ETag it previously received:

PUT /api/products/123 HTTP/1.1 Host: example.com If-Match: "abc123" Content-Type: application/json {"name": "New Name"} HTTP/1.1 412 Precondition Failed Content-Type: application/json { "error": "Precondition failed: resource has been modified", "current_etag": "xyz789" }

The client should GET the latest version, merge its changes, and retry with the new ETag.

412 vs. 409 Conflict

StatusWhen It HappensTypical Use
412 Precondition FailedBefore attempting the operation β€” preconditions fail.Strict conditional requests (e.g., PUT with If-Match).
409 ConflictDuring or after attempting the operation β€” state conflict.More general conflict (e.g., duplicate key, state machine violation).

In practice, many APIs use 409 for both cases because it provides more flexibility and is better supported by clients. However, 412 is the correct status when the failure is specifically due to a precondition header.

When to Use 412

  • For idempotent updates – to prevent lost updates in concurrent environments.
  • For caching – If-None-Match and If-Modified-Since are used to validate cached responses (usually returns 304 Not Modified, not 412).
  • For optimistic locking – ensuring the client's version matches the current version before applying changes.

How to Fix 412 Errors

  • If you're a client developer: Retrieve the latest version of the resource (GET), merge your changes, and retry with the new ETag. If you're using conditional requests for caching, simply use your cached copy if 412 is returned (or handle the 304 response).
  • If you're a server developer: Ensure your server correctly handles conditional headers and returns 412 when preconditions fail. Provide helpful error messages that include the current ETag or last modified date.
  • If you're an end‑user: This error usually means the resource has been updated by someone else. Refresh the page and try again.

Frequently Asked Questions

Is 412 Precondition Failed a client error or a server error?

It's a client error (4xx). The client's conditional headers did not match the server's current state, so the request cannot be fulfilled as specified.

What is an ETag and why is it used?

An ETag (entity tag) is a unique identifier for a specific version of a resource. It is used in conditional requests to detect changes. If the ETag changes, the resource has been modified.

Can I use 412 for validation errors?

No, 412 is specifically for precondition failures. For validation errors, use 422 Unprocessable Entity.