412 Precondition Failed means: A conditional request header evaluated to false: If-Match, If-Unmodified-Since or similar preconditions failed, meaning the resource changed since the client last saw it. It is the backbone of optimistic concurrency control. Client-error 4xx codes mean the request itself is the problem: malformed syntax, missing credentials, forbidden access, a nonexistent resource or a violated precondition. The server is telling the client what to change; retrying the identical request without a fix will reproduce the same error. In practice you will meet 412 when if-match etag no longer matches because another client updated the resource; if-unmodified-since is older than the resource's last modification; a distributed lock or compare-and-swap implemented via conditional headers. On the client side, re-fetch the resource, merge your changes onto the new version, and retry with the fresh ETag — do not blindly strip the precondition. On the server side, implement conditional headers correctly and return 412 (not 200) when they fail; document the ETag lifecycle for API consumers.
When 412 happens
- If-Match ETag no longer matches because another client updated the resource
- If-Unmodified-Since is older than the resource's last modification
- A distributed lock or compare-and-swap implemented via conditional headers
How to fix it
On the client
Re-fetch the resource, merge your changes onto the new version, and retry with the fresh ETag — do not blindly strip the precondition.
On the server
Implement conditional headers correctly and return 412 (not 200) when they fail; document the ETag lifecycle for API consumers.
Should you retry?
Not retryable as-is: change the request (credentials, payload, URL) first.
Debugging steps
When 412 appears unexpectedly, start by capturing the full exchange: 'curl -i' or the browser DevTools Network tab shows the exact status line and response headers, which often carry the real explanation. Read the error body first — well-designed APIs name the offending field or missing credential. Then diff your actual request, headers included, against the documented contract. For this code specifically, check whether the most common trigger applies to your situation: if-match etag no longer matches because another client updated the resource. Compare your exchange against the raw HTTP example above. If you operate the server, correlate the timestamp with application and proxy logs using the request id; if you are the client, verify the request shape against the API documentation before changing anything or retrying.
Notes & gotchas
412 is the precise signal for optimistic concurrency control: combined with If-Match ETags it makes lost updates impossible, because the second writer must merge instead of overwriting.
Examples
HTTP/1.1 412 Precondition Failed
ETag: "v3-def456"
Content-Type: application/json
Content-Length: 128
{
"error": "precondition_failed",
"message": "If-Match ETag no longer matches because another client updated the resource"
} curl -i -X PUT -H 'If-Match: "v2-abc123"' -H "Content-Type: application/json" -d @update.json https://api.example.com/v1/resource const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 412) {
const problem = await res.json(); // read field-level details
// fix the request (credentials, payload, URL) — identical retries keep failing
throw new RequestError(problem);
} import requests
res = requests.get("https://api.example.com/v1/resource", timeout=10)
if res.status_code == 412:
problem = res.json() # field-level error details
# correct the request before retrying — identical retries keep failing
raise RequestProblem(problem) Frequently asked questions
412 vs 409 for lost updates?
412 is the precise signal when you used conditional headers; 409 is the general state-conflict answer. APIs doing optimistic locking should prefer 412 with If-Match.
What is the difference between If-Match and If-None-Match?
If-Match requires the ETag to match (for safe updates, fails with 412); If-None-Match requires it NOT to match (for cache revalidation, fails with 304).
Are 4xx errors always the client's fault?
By contract yes — the server asserts the request must change. In practice servers sometimes misuse 4xx for their own problems (e.g. 400 for internal validation bugs), so read the error body before blaming your client code.
Should I retry 4xx responses automatically?
Generally no: the server says the request must change. Exceptions are 408 (fresh connection), 425 (after handshake) and 429 (after Retry-After). Blind retries of 400/401/403/404 just burn quota.
Try the JSON Validator
Check JSON syntax and locate errors by line and column.