Skip to content

refactor(ratelimit): use RateLimitError for 429 response - #205

Merged
Him-an-shi merged 1 commit into
Him-an-shi:mainfrom
sanket1035:refactor/rate-limiter-apperror
Jul 30, 2026
Merged

refactor(ratelimit): use RateLimitError for 429 response#205
Him-an-shi merged 1 commit into
Him-an-shi:mainfrom
sanket1035:refactor/rate-limiter-apperror

Conversation

@sanket1035

Copy link
Copy Markdown
Contributor

Description

Resolves #164.

Refactors the rate limiting middleware in backend/middleware/rate_limit.py to use the centralized RateLimitError class from utils.errors.

Changes Included:

  • backend/middleware/rate_limit.py:
    • Imported RateLimitError from utils.errors.
    • Refactored rate_limit_exceeded_handler to instantiate RateLimitError with retry_after payload and generate response using .to_dict().
    • Standardized JSON response format: { "error": "...", "code": "RATE_LIMITED", "retry_after": ..., "payload": { "retry_after": ... } }.
    • Preserved the HTTP Retry-After header.
  • backend/middleware/error_handler.py:
    • Delegated 429 error handler directly to rate_limit_exceeded_handler.
  • backend/tests/test_rate_limit.py:
    • Added assertion for "code": "RATE_LIMITED" in 429 response body format test.

How to Test

Run pytest from backend/:

pytest tests/test_rate_limit.py
pytest tests/test_error_handling.py

@vercel

vercel Bot commented Jul 26, 2026

Copy link
Copy Markdown

@sanket1035 is attempting to deploy a commit to the himanshipathak-240263-3015's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Him-an-shi

Copy link
Copy Markdown
Owner

@sanket1035 please resolve merge conflicts

@sanket1035

Copy link
Copy Markdown
Contributor Author

Solved please check out @Him-an-shi

@Him-an-shi
Him-an-shi merged commit 91ba2d2 into Him-an-shi:main Jul 30, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Update rate limiter to use centralized AppError hierarchy

2 participants