Skip to content

feat: expose full rate limit headers on RateLimitError #6

@0xneobyte

Description

@0xneobyte

Problem

The backend returns the following headers on 429 responses:

  • X-RateLimit-Limit-PerMinute
  • X-RateLimit-Remaining-PerMinute
  • X-RateLimit-Limit-PerDay
  • X-RateLimit-Remaining-PerDay
  • Retry-After

The SDK currently only parses Retry-After and discards the rest. Callers have no way to know which limit was hit or what the limit value is, making it impossible to implement informed backoff or meaningful error messages.

Proposed Behaviour

Parse all rate limit response headers and expose them as fields on RateLimitError.

} catch (e) {
  if (e instanceof RateLimitError) {
    console.log(e.retryAfter)      // seconds to wait
    console.log(e.limitPerMinute)  // per-minute cap, or undefined
    console.log(e.limitPerDay)     // per-day cap, or undefined
  }
}

Files to Modify

File Change
src/errors.ts Add limitPerMinute, limitPerDay fields to RateLimitError
src/client.ts Parse additional headers in handleErrorResponse

Acceptance Criteria

  • RateLimitError.retryAfter behaviour is unchanged
  • RateLimitError.limitPerMinute set when header is present
  • RateLimitError.limitPerDay set when header is present
  • Fields are undefined when the corresponding header is absent
  • Tests cover both per-minute and per-day header scenarios

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions