HTTP

HTTP 412 Precondition Failed vs 428 Precondition Required

Both HTTP 412 (Precondition Failed) and 428 (Precondition Required) belong to the 4xx Client Error category. 412 indicates that one or more conditions in the request headers (If-Match, If-Unmodified-Since) evaluated to false. Meanwhile, 428 means that the server requires the request to be conditional (e.g., include If-Match header) to prevent lost updates.

Description

One or more conditions in the request headers (If-Match, If-Unmodified-Since) evaluated to false.

When You See It

When using conditional requests with ETags and the resource has changed.

How to Fix

Refresh the ETag/Last-Modified value and retry with updated preconditions.

Description

The server requires the request to be conditional (e.g., include If-Match header) to prevent lost updates.

When You See It

When an API requires optimistic concurrency control via ETags.

How to Fix

Fetch the resource first to get its ETag, then include If-Match in your update request.

Key Differences

1.

HTTP 412: One or more conditions in the request headers (If-Match, If-Unmodified-Since) evaluated to false.

2.

HTTP 428: The server requires the request to be conditional (e.g., include If-Match header) to prevent lost updates.

3.

You encounter 412 when when using conditional requests with ETags and the resource has changed.

4.

You encounter 428 when when an API requires optimistic concurrency control via ETags.

When to Use Which

For 412 (Precondition Failed): Refresh the ETag/Last-Modified value and retry with updated preconditions. For 428 (Precondition Required): Fetch the resource first to get its ETag, then include If-Match in your update request.

Learn More