Skip to content

fix: surface the reason of every error body - #23

Merged
1pxone merged 1 commit into
mainfrom
fix/error-body-shapes
Nov 15, 2026
Merged

1pxone merged 1 commit into
mainfrom
fix/error-body-shapes

Conversation

@1pxone

@1pxone 1pxone commented Nov 15, 2026

Copy link
Copy Markdown
Member

A failed request now raises an Error whose message is "<status> <reason>" for every error body the SDK can receive, and carries code and retryable when the server sends them.

Bug: in direct mode, the engine answers an auth failure (a bad token, or a read-only capability attempting a write) with {"error":"unauthorized"}, where error is a string. The SDK read error.message and reported 401 engine request failed, losing the reason.

Fix: one parser, src/network/errors.ts, used by direct engine mode, the HTTP client and uploads. It handles:

  • the protocol envelope {"error":{"code","message","retryable"}}
  • a bare string error
  • RushDB Cloud error bodies
  • non-JSON and empty bodies, which keep the HTTP status

Tests: test/error-bodies.spec.ts (Node and fetch clients against every shape) and test/direct-engine.live.spec.ts against a local engine (set RUSHDB_TEST_ENGINE_URL, RUSHDB_TEST_ENGINE_TOKEN and RUSHDB_TEST_ENGINE_CAPABILITY_SECRET, with the engine started with --capability-secret). Types and build clean; 165 unit tests and 14 live tests pass. Successful calls are unchanged.

Patch changeset, no public API change.

The engine answers auth failures on its protocol endpoints with a bare
string, {"error":"unauthorized"}, while protocol errors use the envelope
{"protocolVersion":1,"error":{"code","message","retryable"}}. Direct mode
read only error.message, so a bad token or a write with a read-only
capability surfaced as "401 engine request failed"; the HTTP client read
only a string error, so it dropped the reason of an envelope.

One parser in network/errors.ts now serves direct mode, the HTTP client
and uploads. It reads the envelope, a bare string error and a RushDB
Cloud error, and keeps the status for an empty or non-JSON body. The
error carries code and retryable when the server sends them.
@1pxone
1pxone merged commit 1a962cf into main Nov 15, 2026
1 check passed
@1pxone
1pxone deleted the fix/error-body-shapes branch November 15, 2026 20:17
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