Error Codes Wiki

HTTP 412 Precondition Failed — What It Means & How to Fix It

Error4xx client error

Overview

The HTTP 412 Precondition Failed status code indicates one or more conditions specified in the request headers evaluated to false on the server.

Key Details

  • This occurs when conditional headers like If-Match or If-Unmodified-Since fail their checks.
  • It is used in optimistic concurrency control to prevent lost updates.
  • The client should fetch the latest version and retry with updated preconditions.
  • Common in APIs that use ETags for conflict detection.

Common Causes

  • The If-Match header contains an ETag that no longer matches the current resource.
  • The If-Unmodified-Since date is older than the resource last modification time.
  • Another client modified the resource between your GET and PUT/PATCH.

Steps

  1. 1Fetch the latest version of the resource to get the current ETag.
  2. 2Merge your changes with the latest version.
  3. 3Retry the request with the updated ETag in the If-Match header.
  4. 4Implement retry logic for concurrent modification scenarios.

Tags

httpclient-errorpreconditionetagconcurrency

Related Items

More in 4xx Client Error

Frequently Asked Questions

It means a condition specified in the request headers (like If-Match or If-Unmodified-Since) was not met. The resource may have been modified by someone else.