-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Background
WatsonX APIs return detailed, structured error responses when requests fail, including:
- HTTP status codes (e.g., 400, 401, 403, 429, 5xx)
- API-specific error codes and messages
- Optional trace IDs for debugging
Currently, the watsonx-go client:
- Converts all failures into a generic error (e.g.,
400 Bad Request) - Does not propagate structured WatsonX error details
- Fails to support safe retries when the request body is consumed on the first attempt
This leads to incomplete or misleading error information for callers and makes implementing reliable retry logic difficult.
Problem
- WatsonX API error responses are not propagated to the caller
- HTTP status codes are effectively masked
- Retry logic fails: the first attempt returns the correct WatsonX error, but subsequent attempts return
400 Bad Requestbecause the HTTP request body has already been consumed - Client applications cannot reliably inspect, log, or act on WatsonX-specific error details
Proposed Solution
-
Structured error propagation
- Return non-2xx WatsonX HTTP responses as structured errors
- Include HTTP status codes, error codes, and trace IDs in the returned error
- Implement
Error()for human-readable logging, while allowing type inspection viaerrors.As
-
Safe retry support
- Ensure HTTP request bodies are reusable across retry attempts
- Avoid hardcoding retry logic based on error strings; instead, use status codes and structured errors to decide retryable cases
Benefits
- Provides detailed WatsonX API errors to clients
- Supports safe retries for transient failures (e.g., 429, 5xx)
- Preserves HTTP status codes and error information for inspection
- Maintains backward compatibility for generic error handling
Notes / References
- PR expose watsonx API errors to callers sbpolar/watsonx-go#1 demonstrates structured WatsonX error propagation using the
DecodeWatsonxErrorfunction. - The current
retry.goimplementation fails on retries because the HTTP request body is consumed after the first attempt.
Metadata
Metadata
Assignees
Labels
No labels