HTTP

HTTP 400 Bad Request vs 412 Precondition Failed

Both HTTP 400 (Bad Request) and 412 (Precondition Failed) belong to the 4xx Client Error category. 400 indicates that the server cannot process the request due to malformed syntax, invalid request message framing, or deceptive request routing. Meanwhile, 412 means that one or more conditions in the request headers (If-Match, If-Unmodified-Since) evaluated to false.

Description

The server cannot process the request due to malformed syntax, invalid request message framing, or deceptive request routing.

When You See It

When sending malformed JSON, missing required fields, or invalid query parameters.

How to Fix

Check the request body format, validate all required fields, and ensure proper encoding.

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.

Key Differences

1.

HTTP 400: The server cannot process the request due to malformed syntax, invalid request message framing, or deceptive request routing.

2.

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

3.

You encounter 400 when when sending malformed JSON, missing required fields, or invalid query parameters.

4.

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

When to Use Which

For 400 (Bad Request): Check the request body format, validate all required fields, and ensure proper encoding. For 412 (Precondition Failed): Refresh the ETag/Last-Modified value and retry with updated preconditions.

Learn More