Skip to content

Add typed RateLimitException and ForbiddenException - #8

Merged
mathiasgrimm merged 4 commits into
mainfrom
feat/rate-limit-forbidden-exceptions
Jul 20, 2026
Merged

Add typed RateLimitException and ForbiddenException#8
mathiasgrimm merged 4 commits into
mainfrom
feat/rate-limit-forbidden-exceptions

Conversation

@mathiasgrimm

Copy link
Copy Markdown
Owner

What

  • RateLimitException (extends ApiException) is thrown on 429 responses. It carries retryAfterSeconds, parsed from the Retry-After header in both RFC 9110 forms (delay-seconds and HTTP date), clamped to never be negative and rounded up, so a caller can sleep() the value as-is. Missing or unparseable headers yield null.
  • ForbiddenException (extends ApiException) is thrown on 403 responses with the API's message.
  • Both stay catchable as ApiException, locked by a test, so existing consumers keep working.

Why

The glimpse CLI is gaining a built-in public analyze-only token so glimpse check works on fork pull requests (see glimpseimg.com PR #77). The CLI needs to retry rate limits with backoff and explain ability rejections; the generic ApiException could not carry either signal.

Release

Tag as v2.1.0 after merge. The glimpse-cli PR depends on this release.

Reviewed by codex and claude CLIs; their findings (HTTP-date parsing, clamping, message preservation, catchability test) are included.

🤖 Generated with Claude Code

mathiasgrimm and others added 3 commits July 20, 2026 12:21
429 responses now throw RateLimitException carrying the Retry-After
delay in seconds, and 403 responses throw ForbiddenException with the
API message, so the CLI can retry rate limits with backoff and explain
ability rejections (the public CI token hitting a non-analyze endpoint)
instead of collapsing both into the generic ApiException.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Apply the review findings from codex and claude: parse the HTTP-date
form of Retry-After, clamp negative and round up fractional delays so
callers can sleep the value as-is, prefer the API's message over the
hardcoded fallback, and lock the new exceptions' ApiException
catchability in tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
GlimpseImg\ becomes MathiasGrimm\GlimpsePhp\, aligning the SDK with
the MathiasGrimm vendor namespace used across the other packages.
Breaking change: consumers must update their imports. The Composer
package name stays mathiasgrimm/glimpse-php.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…limpsephp

Rename the namespace to MathiasGrimm\GlimpsePhp
@mathiasgrimm
mathiasgrimm merged commit c4bd182 into main Jul 20, 2026
6 checks passed
@mathiasgrimm
mathiasgrimm deleted the feat/rate-limit-forbidden-exceptions branch July 20, 2026 17:31
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.

1 participant