Qaynaq LABS · TOOLS

HTTP · 4xx Client Error

412 Precondition Failed

Request headers specified preconditions not met by the server.

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

  1. Verify conditional headers in client request.
  2. Check server resource ETag/Last-Modified values.
  3. Compare client and server timestamps.
  4. 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.

Frequently asked

Why does 412 occur with If-None-Match: *?

412 happens when the resource exists (ETag matches). Use 304 for unchanged resources.

Can 412 be used for optimistic concurrency control?

Yes, clients send If-Match with expected ETag; 412 indicates mismatch.

Is 412 safe to retry automatically?

No, retrying without fixing the precondition may cause infinite loops.