HTTPError.net

The fastest way to diagnose, understand, and fix any HTTP status code

412 Precondition Failed

Fault: Client
TL;DR

A conditional request (If-Match, If-Unmodified-Since, etc.) failed, so the server did not perform the operation. Commonly used to prevent the 'lost update' problem.

One or more conditions in the request headers evaluated to false.

What HTTP 412 Precondition Failed Means

One or more conditions in the request headers evaluated to false.

A conditional request (If-Match, If-Unmodified-Since, etc.) failed, so the server did not perform the operation. Commonly used to prevent the 'lost update' problem.

Common Causes

How to Fix It (For Visitors)

How to Fix It (For Developers/Admins)

Returning a 412 Precondition Failed (Code Examples)

If you build APIs or web apps, here is how to send an HTTP 412 response and how to test for it:

Node.js (Express)

app.get('/resource', (req, res) => {
  res.status(412).json({ error: 'Precondition Failed' });
});

Python (Flask)

@app.route('/resource')
def resource():
    return jsonify(error='Precondition Failed'), 412

PHP

<?php
http_response_code(412);
header('Content-Type: application/json');
echo json_encode(['error' => 'Precondition Failed']);

Check the status with curl

curl -I https://example.com/resource
# Look for: HTTP/1.1 412 Precondition Failed

Frequently Asked Questions

What does HTTP 412 Precondition Failed mean?

A conditional request (If-Match, If-Unmodified-Since, etc.) failed, so the server did not perform the operation. Commonly used to prevent the 'lost update' problem. In short: One or more conditions in the request headers evaluated to false.

Is 412 Precondition Failed a client or server error?

412 is a 4xx client-error code, so the request itself needs to change. The server is running normally and is rejecting the request as it was sent by the browser, app, or API client.

How do I fix a 412 Precondition Failed error?

Re-fetch the resource to obtain the current ETag. Send the updated If-Match value. Handle 412 by prompting the user to merge changes.

Official Specification

The 412 Precondition Failed status code is defined in RFC 9110 Section 15.5.13.

View the IANA HTTP Status Code Registry →