Precondition Failed
4xx Client Error
Last updated:
A precondition given in the request headers (e.g. If-Match) evaluated to false.
Description
Used with ETag-based concurrency control. If the client sends If-Match: 'v1' but the server's current ETag is 'v2', respond with 412.
When to use
Return 412 on optimistic locking failures where an If-Match / If-Unmodified-Since header didn't match.
Specification
RFC 9110 §15.5.13
Examples
HTTP response
HTTP/1.1 412 Precondition Failed
Content-Type: application/json
{"error":"Precondition Failed"}Node.js (Express)
res.status(412).json({ error: "Precondition Failed" });Go (net/http)
w.WriteHeader(http.Status412)
Python (Flask)
return jsonify({"error": "Precondition Failed"}), 412Related status codes
All 4xx codes
400 Bad Request401 Unauthorized403 Forbidden404 Not Found405 Method Not Allowed406 Not Acceptable408 Request Timeout409 Conflict410 Gone411 Length Required412 Precondition Failed413 Payload Too Large414 URI Too Long415 Unsupported Media Type418 I'm a teapot422 Unprocessable Entity425 Too Early428 Precondition Required429 Too Many Requests431 Request Header Fields Too Large451 Unavailable For Legal Reasons