412
HTTPERRORNotable4xx Client ErrorHIGH confidence

Precondition Failed

Production Risk

Low. This is the correct and expected behavior for implementing optimistic concurrency control. It prevents data corruption.

What this means

The client has indicated preconditions in its headers which the server does not meet. This is typically used for conditional requests, for example, to prevent 'lost update' problems where a client GETs, modifies, and PUTs a resource back to the server.

Why it happens
  1. 1A client tries to update a resource with a 'If-Match' header, but the ETag on the server has changed.
  2. 2A client uses an 'If-Unmodified-Since' header, but the resource has been modified recently.
  3. 3The request specifies a condition that the server resource state does not fulfill.
How to reproduce

An application tries to update a document, but another user has already modified it, so the ETag in the 'If-Match' header is no longer valid.

trigger — this will error
trigger — this will error
PUT /api/documents/123 HTTP/1.1
Host: example.com
If-Match: "stale-etag"

{ "content": "updated content" }

expected output

HTTP/1.1 412 Precondition Failed

Fix

Refresh Data and Resubmit

WHEN A conditional request fails.

Refresh Data and Resubmit
The client should re-fetch the resource to get the latest data and ETag, then re-apply its changes and resubmit.

Why this works

Client-Side Logic

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All HTTP errors