Skip to content

Use the standard error format for 429 responses and send Retry-After - #763

Merged
marcvergees merged 1 commit into
fireform-core:developmentfrom
1sakshm:762-rate-limit-error-envelope
Nov 10, 2026
Merged

marcvergees merged 1 commit into
fireform-core:developmentfrom
1sakshm:762-rate-limit-error-envelope

Conversation

@1sakshm

@1sakshm 1sakshm commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #762

Problem

The rate limit handler added in #761 answered 429 with {"success": false, "error": "RATE_LIMIT_EXCEEDED", "message": ...}. Every other error uses {error_code, message, detail?}. As a result:

  • The frontend's extractErrorMessage reads body.error first, so a rate-limited user saw the raw code "RATE_LIMIT_EXCEEDED" instead of the message.
  • Nothing told the client when it could try again.

Change

  • app/api/middleware/rate_limiter.py: the 429 body is now {"error_code": "RATE_LIMIT_EXCEEDED", "message": "Too many requests. Limit: 10 per 1 minute", "retry_after_seconds": N}, and the response includes a matching Retry-After: N header.
    • N is read from the limiter's current window (the same get_window_stats call slowapi uses for its own headers), so it is the actual time until the limit resets. It falls back to 60 if that lookup fails.
  • Contracts: documented the 429 response on GET /templates, POST /templates/upload and POST /forms/fill. retry_after_seconds in ErrorResponse now mentions 429.

The limits themselves are unchanged.

Tests

  • test_rate_limit_forms_fill now checks the new body, that the old success/error keys are gone, and that the Retry-After header matches retry_after_seconds. It fails on development with KeyError: 'error_code'.
  • Manual check: after 10 calls to GET /templates and a 3-second wait, the 11th returns 429, Retry-After: 57, {'error_code': 'RATE_LIMIT_EXCEEDED', 'message': 'Too many requests. Limit: 10 per 1 minute', 'retry_after_seconds': 57}.
  • Full suite: 457 passed. ruff check app/ is clean.

The rate limit handler answered {success, error, message}, unlike every
other error ({error_code, message}). The frontend reads body.error first,
so users saw the raw code instead of the message. Return error_code and
message, plus retry_after_seconds and a Retry-After header taken from the
limiter's window, and document the 429 in the contracts.

Fixes fireform-core#762
@marcvergees
marcvergees merged commit 94b2c9d into fireform-core:development Nov 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: 429 rate-limit response uses a different error format and has no Retry-After

2 participants