feat: expose structured API errors via RequestError#15
Merged
Conversation
ABujalance
approved these changes
May 14, 2026
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.
feat: Expose structured API errors via
RequestErrorSummary
Introduces a new
RequestErrorclass that replaces the genericErrorthrown byEngineServicesClienton non-2xx HTTP responses. It parses the structured JSON body the platform returns ({ message, code?, details? }) and exposes each field as a typed property, so callers can react to specific failure conditions without string-matching an error message.Motivation
The platform API already returns machine-readable error codes (e.g.
LIMIT_EXCEEDED) in its response body. Before this change, all HTTP failures were surfaced as a plainErrorwhose message was a concatenated status line — forcing consumers to do fragile substring searches to distinguish a 401 from a quota error. This PR makes that contract explicit and testable.Changes
src/core/request-error.ts(new)RequestError extends Errorwith readonly properties:status: number— HTTP status code.code?: string— machine-readable error code from the response body (e.g.'LIMIT_EXCEEDED').details?: unknown— arbitrary details object from the response body.body: string— raw response body for diagnostics."<statusText> (<status>)"as the message with nocodeordetails.src/index.ts).src/core/client.tsthrow new Error(...)in the HTTP failure path withthrow new RequestError(status, statusText, body).src/cli/commands/publish.tsmessage.includes('401')/message.includes('403')checks withinstanceof RequestError+err.status/err.codeguards.LIMIT_EXCEEDED(prints the API message verbatim), 401 (login hint), 403 (permission denied), and a generic fallback.ECONNREFUSED,fetch) are still caught separately through the outerelsebranch.src/cli/templates/test/src/main.tserr.message.includes("4")(heuristic 4xx detection) with a proper check onerr.statususing the new structured shape (status >= 400 && status < 500).Tests
src/core/request-error.test.ts(new)instanceof Error/instanceof RequestErroridentitysrc/core/client.test.tsrejects.toMatchObject({ name: 'RequestError', status, code, message })Breaking changes
None.
RequestErroris a subclass ofError, so any existingcatch (err)that only readserr.messagecontinues to work. The new class is purely additive.Changeset
minor— new public exportRequestError.