# 412 Precondition Failed

> https://http-status.org/docs/412

**Family:** 4xx Client Error

## Rationale

One or more conditions given in request header fields evaluated to false by the server.

## In Plain Terms

You said 'only do this if that thing is true', but that thing turned out to be false, so I didn't do anything.

## Description

The HTTP 412 Precondition Failed status code indicates that one or more conditions given in the request header fields evaluated to false when tested on the server.

## Server Perspective

### Usage
- Return 412 for failed If-Match, If-Unmodified-Since, or similar explicit request preconditions
- Use it to stop stale writes or invalid conditional operations before they change state
- If-Match header doesn't match current ETag
- If-Unmodified-Since header fails time check
- If-None-Match header matches current ETag
- Conditional updates that fail preconditions

### Implementation
- Explain which precondition failed when that helps client recovery
- Keep 412 distinct from 428, which is about a missing required precondition

### Common Headers
- If-Match
- If-None-Match
- If-Unmodified-Since
- If-Modified-Since

### Body
- Optionally include which precondition failed and the current validator when safe to expose.

### Pitfalls
- Use 409 for broader state conflicts that are not tied to a specific conditional header
- Do not use 412 when the required precondition header was missing entirely; use 428
- General conflicts (use 409 Conflict)
- Missing preconditions (use 428 Precondition Required)
- Authentication issues (use 401 Unauthorized)

## Client Perspective

### Pitfalls
- Do not blindly retry the same stale conditional request

## Examples

### Conditional update with outdated ETag

Resource was modified since client last fetched it, ETag no longer matches

**Request:**
```
PUT https://api.example.test/api/users/123
If-Match: "old-etag"
```

**Response:**
```
412 Precondition Failed
Content-Type: application/json

{
  "error": "precondition_failed"
}
```

## Related Codes

- [409 Conflict](/docs/409.md)
- [428 Precondition Required](/docs/428.md)
- [304 Not Modified](/docs/304.md)

