Skip to content

fix: map HTTP 402 and 413 to status-specific exceptions - #9

Merged
garretpremo merged 1 commit into
Premo-Cloud:mainfrom
Ashfaqbs:fix/402-413-exception-mapping
Sep 21, 2026
Merged

garretpremo merged 1 commit into
Premo-Cloud:mainfrom
Ashfaqbs:fix/402-413-exception-mapping

Conversation

@Ashfaqbs

Copy link
Copy Markdown

Motivation:
TypeSafeApiException.fromResponse maps 400/401/403/404/422/429/5xx to status-specific exceptions, but 402 (out of credits) and 413 (payload too large) fell through to the generic TypeSafeApiException, same as an arbitrary unmapped status. Both are documented, actionable API responses. The JS SDK has the identical gap, reported today as typesafe-ai/typesafe-sdk-js#13.

Changes:

  • TypeSafePaymentRequiredException and TypeSafePayloadTooLargeException, one-line subclasses matching the existing style (e.g. TypeSafeBadRequestException)
  • Two new case arms in TypeSafeApiException.fromResponse
  • Two assertions added to errorsMapToStatusSpecificExceptionsWithExtractedMessages covering the new mappings
  • CHANGELOG entry

Neither status is in RetryPolicy.DEFAULT_HTTP_STATUSES, so no retry-behavior change.

Result:
./gradlew :typesafe-sdk:check passes.

Fixes: #8

Both fell through to the generic TypeSafeApiException, unlike every
other documented status (400/401/403/404/422/429/5xx). Fixes Premo-Cloud#8.
@xbt-a4224j

Copy link
Copy Markdown
Contributor

LGTM!

@garretpremo garretpremo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: subclasses match the existing one-liners, switch arms in status order, tests cover both messages, changelog references #8. CI green.

@garretpremo
garretpremo merged commit 4805f47 into Premo-Cloud:main Sep 21, 2026
1 check passed
garretpremo added a commit that referenced this pull request Sep 22, 2026
Requests, retries and connection failures log at DEBUG on the
io.github.premocloud.typesafe logger, with the wire at TRACE and
credential headers masked; nothing at INFO or above. Each call's lines
share a short random tag so interleaved async calls stay readable. Adds
org.slf4j:slf4j-api as an api dependency (#6, #7).

HTTP 402 and 413 now raise TypeSafePaymentRequiredException and
TypeSafePayloadTooLargeException instead of the generic
TypeSafeApiException (#8, #9). READMEs point at 0.4.0.
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.

402 and 413 fall through to the generic exception, unlike every other mapped status

5 participants