feat: add BlaxelAPIError with auto-throw on 4xx/5xx responses#295
Open
devin-ai-integration[bot] wants to merge 4 commits into
Open
feat: add BlaxelAPIError with auto-throw on 4xx/5xx responses#295devin-ai-integration[bot] wants to merge 4 commits into
devin-ai-integration[bot] wants to merge 4 commits into
Conversation
- Create BlaxelAPIError class in @blaxel/core/src/client/errors.ts - Add apiErrorInterceptor that throws BlaxelAPIError on HTTP 4xx/5xx, matching the Go SDK's auto-raise behaviour - Add throwOnError config option (true by default, opt-out via false) - Update ResponseError to extend BlaxelAPIError for consistency - Export BlaxelAPIError from the package's public API - Add Error handling section to README with usage examples Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…tch blocks The SDK's createIfNotExists/get methods catch errors and check e.code to distinguish expected 404/409 from unexpected errors. BlaxelAPIError now exposes a .code property that reflects the code field from the API JSON body (e.g. 409 or 'SANDBOX_ALREADY_EXISTS'), falling back to the HTTP status code. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ng response.status The response interceptor now throws BlaxelAPIError before the caller can inspect response.status. Use try/catch with BlaxelAPIError code check (matching the pattern used by createIfNotExists) instead. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…etion When settings.throwOnError is false, the apiErrorInterceptor skips and hey-api/client-fetch throws the parsed JSON body directly (a plain object with .code, not a BlaxelAPIError). Add a fallback check for plain objects with code === 404 so waitForDeletion works regardless of the throwOnError setting. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
LGTM
The previous waitForDeletion bug is correctly fixed in commit 925ff83: the fallback "code" in e && e.code === 404 handles the hey-api plain-object throw when throwOnError: false. The rest of the PR is well-structured and the implementation is correct.
Tag @mendral-app with feedback or questions. View session
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.
Summary
The control plane API client (generated
@hey-api/client-fetch) does not automatically throw on 4xx/5xx responses — it returns typed error objects or undefined. The Go SDK auto-raises on all 4xx/5xx (sdk-go internal/requestconfig/requestconfig.go:526). This PR brings the TypeScript SDK to parity.Changes
BlaxelAPIError(@blaxel/core/src/client/errors.ts) — new error class withstatusCode,errorBody,response, optionalerrorCode, and acodeproperty that mirrors the API body'scodefield (or falls back to the HTTP status). Thecodeproperty ensures backward compatibility with existingcatchblocks that checke.code.apiErrorInterceptor(@blaxel/core/src/client/responseInterceptor.ts) — response interceptor that runs afterauthenticationErrorInterceptor, checksresponse.status >= 400, parses the JSON body, and throwsBlaxelAPIError. Gated bysettings.throwOnError.throwOnErrorconfig option (@blaxel/core/src/common/settings.ts) — added to theConfigtype andSettingsclass. Defaults totrue(auto-raise). Users can opt out withinitialize({ throwOnError: false }).ResponseErrorextendsBlaxelAPIError(@blaxel/core/src/sandbox/action.ts) — sandbox operations now throw aResponseErrorthat is aninstanceof BlaxelAPIError, maintaining backward compatibility for code that catchesResponseErrorwhile also being catchable asBlaxelAPIError.waitForDeletionupdated (@blaxel/core/src/sandbox/preview.ts) — updated to use try/catch withBlaxelAPIErrorinstead of manually checkingresponse.status, since the interceptor now throws before the caller can inspect the response.Public export —
BlaxelAPIErroris exported from@blaxel/coreviaclient/client.ts.README — added "Error handling" section with try/catch examples and opt-out instructions.
Review & Testing Checklist for Human
throwOnError: trueby default, any existing code that calls control-plane SDK functions (e.g.listAgents,getAgent) and inspects{ data, error }tuples without try/catch will now get uncaught exceptions. Verify this is the desired migration path.codeproperty semantics:BlaxelAPIError.codeprefers thecodefield from the JSON body (e.g.409or"SANDBOX_ALREADY_EXISTS"), falling back tostatusCode. Verify this matches existing catch block assumptions.initialize({ throwOnError: false })and verify control-plane calls return{ data, error }tuples without throwing.Notes
authenticationErrorInterceptor(which enriches 401/403 bodies with doc links) runs first, soBlaxelAPIError.errorBodyfor auth errors will include thedocumentationfield.expected 1 to be +0)..codeproperty and updatingwaitForDeletion.Link to Devin session: https://app.devin.ai/sessions/1a9828aa9ec040c99f724380cee61669
Requested by: @Joffref
Note
This PR adds a
BlaxelAPIErrorclass and anapiErrorInterceptorthat auto-throws on HTTP 4xx/5xx responses, bringing the TypeScript SDK to parity with the Go SDK's behavior. It makesResponseErrorextendBlaxelAPIErrorfor a unified error hierarchy, adds athrowOnErroropt-out config option, and updateswaitForDeletionto use try/catch instead of inspectingresponse.status.Written by Mendral for commit 925ff83.