Repository navigation
fix: surface the reason of every error body - #23
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A failed request now raises an
Errorwhose message is"<status> <reason>"for every error body the SDK can receive, and carriescodeandretryablewhen 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"}, whereerroris a string. The SDK readerror.messageand reported401 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:{"error":{"code","message","retryable"}}errorTests:
test/error-bodies.spec.ts(Node and fetch clients against every shape) andtest/direct-engine.live.spec.tsagainst a local engine (setRUSHDB_TEST_ENGINE_URL,RUSHDB_TEST_ENGINE_TOKENandRUSHDB_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.