HTTP 421 Misdirected Request indicates the request was directed at a server that cannot or will not produce a response. This is primarily an HTTP/2 concern — when connection coalescing routes a request over a shared connection to a server that isn't authoritative for the requested host. The client should retry the request over a different connection. CDNs and load balancers with multiple virtual hosts are the most common source of 421 errors.
Response includes the status code, standard headers (including Content-Type), and a small diagnostic JSON body describing the request and returned status.
Simulator URL (copy in the app after load — not a normal link):
https://httpstatus.com/api/status/421
Example request:
curl -i "https://httpstatus.com/api/status/421"The request was directed at a server that is not able to produce a response.
On this code, Inspector focuses on semantics, headers, and correctness warnings that commonly affect clients and caches.
HTTP 421 Misdirected Request has specific technical implications for API design, caching, and client behavior. Understanding the precise semantics helps distinguish it from similar status codes and implement correct error handling. The response should include a descriptive body following a consistent error schema (like RFC 7807 Problem Details) so clients can programmatically handle the error.
// Handle 421 Misdirected Request in Express
app.use((err, req, res, next) => {
if (err.status === 421) {
return res.status(421).json({
type: 'https://api.example.com/errors/misdirected-request',
title: 'Misdirected Request',
status: 421,
detail: err.message
});
}
next(err);
});from fastapi import HTTPException
# Raise 421 Misdirected Request
raise HTTPException(
status_code=421,
detail={
'type': 'misdirected_request',
'message': 'Descriptive error for 421 Misdirected Request'
}
)// Spring Boot 421 Misdirected Request handling
@ExceptionHandler(CustomMisdirectedRequestException.class)
public ResponseEntity<ErrorResponse> handleMisdirectedRequest(
CustomMisdirectedRequestException ex) {
return ResponseEntity.status(421)
.body(new ErrorResponse("Misdirected Request", ex.getMessage()));
}// Return 421 Misdirected Request
func errorHandler(w http.ResponseWriter, message string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(421)
json.NewEncoder(w).Encode(map[string]any{
"status": 421,
"error": "Misdirected Request",
"message": message,
})
}