When you see this status
- Client sends If-Match header with ETag not matching current resource.
- Client sends If-Unmodified-Since with timestamp older than resource modification.
- Client sends If-None-Match with ETag matching current resource.
- Client sends If-Modified-Since with timestamp newer than resource modification.
Common causes
- Client cache stale or mismatched ETag.
- Race condition between client request and server update.
- Incorrect conditional headers in API client.
- Server resource modified after conditional request sent.
How to debug it
- Verify conditional headers in client request.
- Check server resource ETag/Last-Modified values.
- Compare client and server timestamps.
- Inspect request headers for If-* conditions.
Return this code in your framework
Express (Node.js)
res.status(412).send('Precondition failed');
FastAPI (Python)
from fastapi import HTTPException
raise HTTPException(status_code=412, detail="Precondition failed")
NestJS
@Get()
getData() {
throw new HttpException('Precondition failed', HttpStatus.PRECONDITION_FAILED);
}
Go (net/http)
w.WriteHeader(http.StatusPreconditionFailed)
w.Write([]byte("Precondition failed"))
About HTTP 412
HTTP status code 412 Precondition Failed is part of the
4xx Client Error family. Request headers specified preconditions not met by the server. Understanding it is essential for
backend engineers, API designers, and anyone debugging integrations between services.
The Qaynaq Labs HTTP Status Code Explainer covers all standard codes with practical guidance:
what triggers them, how to debug them in production, and exactly how to return them from common
frameworks. Each code page is hand-curated and verified.