docs: Improve API error handling for toolbox-core
client
#275
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.
Fixes #273
Problem
Currently, the SDK client unconditionally attempts to parse all API responses as JSON. If the remote server returns an error (e.g., 403 Forbidden due to an authentication failure, or 404 Not Found), the response body is often HTML or plain text, not JSON.
This leads to a low-level
ContentTypeError
, which masks the original, more informative error from the server (like the HTTP status and reason). Users are left with a confusing"response not parseable"
message instead of knowing the true cause of the failure.Solution
This PR introduces a check to validate the HTTP response status before attempting to parse its body.
If the response status is not 200 OK, the client now captures the status code, reason phrase, and the raw response body.
It then raises a
RuntimeError
that includes all of this valuable context.This ensures that the actual error from the server is always surfaced to the user.
Before
After