Skip to content

feat(core): make apiRequest cancellable and safe on unreadable responses - #144

Merged
filipmyllari merged 1 commit into
mainfrom
core-api-request
Dec 2, 2026
Merged

filipmyllari merged 1 commit into
mainfrom
core-api-request

Conversation

@filipmyllari

Copy link
Copy Markdown
Collaborator

Why

Split out of #122 on review. The data commands need apiRequest to be cancellable, to refuse redirects on writes, and to fail cleanly on a response it can't read. These changes affect every caller, so they get their own PR and tests.

What

  • signal: a caller signal, combined with the existing 30s timeout.
  • redirect: an optional redirect policy, passed to fetch. The default (follow) is unchanged.
  • An invalid JSON body on a success now returns a failure ("Invalid JSON response from API.") instead of throwing.
  • Error bodies: only a string message is kept. A non-numeric code falls back to the HTTP status, and a body that isn't JSON falls back to the status text.
  • New apiFailure(message), plus the isRecord, requireRecord and requireString guards in core.

Testing

pnpm qa passes. New flags get CLI tests cover the existing callers: an unreadable success body, a non-JSON error body, and an error with a string code.

🤖 Generated with Claude Code

apiRequest now accepts a caller signal and a redirect policy, returns a
failure instead of throwing on an invalid JSON body, and keeps only a
string message from error bodies. Adds isRecord/requireRecord/requireString
guards and apiFailure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@filipmyllari
filipmyllari merged commit 3bea6ff into main Dec 2, 2026
7 checks passed
@filipmyllari
filipmyllari deleted the core-api-request branch December 2, 2026 13:20
@github-actions github-actions Bot mentioned this pull request Dec 2, 2026
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.

2 participants