Example HTTP Response
HTTP/1.1 412 Precondition Failed
ETag: "new-etag-value"- If-Match header doesn't match ETag
- If-Unmodified-Since condition failed
- Conditional request preconditions not satisfied
What does this mean?
Your conditions weren't met! You said 'only if...' and the server said 'nope, that's not the case.'
Technical Definition
The client has indicated preconditions in its headers which the server does not meet.
RFC Says
"The 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. This response code allows the client to place preconditions on the current resource state (its current representations and metadata) and, thus, prevent the request method from being applied if the target resource is in an unexpected state."
Plain English:
412 means 'The conditions you specified weren't met, so I didn't perform your request.' This is commonly used with headers like If-Match or If-Unmodified-Since for optimistic locking - ensuring you're updating the version of the resource you think you are.
Common Misinterpretation
Don't confuse 412 with 409. Use 412 when conditional headers (If-Match, If-None-Match, If-Modified-Since, etc.) fail. Use 409 for business logic conflicts. 412 is about HTTP-level preconditions, not application-level conflicts.
Ready-to-use code for returning this HTTP status in your application:
// Express.js
app.get('/example', (req, res) => {
res.status(412).json({
error: 'Precondition Failed',
message: 'Your error message here'
});
});
// Native HTTP
const http = require('http');
http.createServer((req, res) => {
res.writeHead(412, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: 'Precondition Failed',
message: 'Your error message here'
}));
}).listen(3000);