RateLimitExceededException, which is automatically converted to an HTTP 429 (Too Many Requests) response by the RateLimitExceptionHandler.
Response format
The exception handler (fromexception/RateLimitExceptionHandler.java:18-61) returns a standardized RFC 7807 Problem Detail response.
Example response
Response body fields
| Field | Type | Description |
|---|---|---|
type | string | Problem type URI (always “about:blank” for generic errors) |
title | string | Human-readable summary (always “Rate limit exceeded”) |
status | integer | HTTP status code (always 429) |
detail | string | Detailed error message including the rate limit key |
timestamp | string | ISO 8601 timestamp when the error occurred |
key | string | The rate limit key that was exceeded |
limit | integer | Maximum requests allowed in the window |
windowSeconds | integer | Time window duration in seconds |
name | string | Optional logical name from @RateLimit(name = "...") |
retryAfterSeconds | integer | Seconds until the rate limit resets |
HTTP headers
The response includes standard rate limit headers whenratelimiter.include-http-headers is enabled (default: true).
Headers included
From the implementation (exception/RateLimitExceptionHandler.java:45-51):| Header | Value | Description |
|---|---|---|
Retry-After | integer | Seconds to wait before retrying (standard HTTP header) |
RateLimit-Limit | integer | Maximum requests allowed in the window |
RateLimit-Remaining | integer | Requests remaining in current window (always 0 when blocked) |
RateLimit-Reset | integer | Seconds until the rate limit resets |
Example headers
Configuration
Disable HTTP headers
You can disable the rate limit headers while keeping the response body:Constructor implementation
The configuration is injected via constructor (fromexception/RateLimitExceptionHandler.java:20-25):
Retry-After calculation
TheRetry-After header is calculated from the rate limit decision (from exception/RateLimitExceptionHandler.java:56-60):
- Uses the
retryAfterduration from the rate limit decision if available - Falls back to the full window duration
- Ensures a minimum of 1 second
Client-side handling
JavaScript/TypeScript example
Java RestTemplate example
Python requests example
Custom exception handler
You can customize the response format by providing your own exception handler:Testing 429 responses
Test that your application correctly returns 429 responses:Best practices
Always respect Retry-After
Clients should always honor theRetry-After header to avoid making unnecessary requests: