Errors and Retries
Validation errors, API errors, and transport retry behavior.
Client-side validation errors
Validation is returned as:
type ValidationError struct {
Field string
Message string
}Error() format:
<field>: <message>These errors happen before network request is sent.
API/server errors
Server errors are parsed into:
type APIError struct {
StatusCode int
Message string
Code string
RawBody string
}Error() includes status code and optional code.
HTTP retry behavior
For normal JSON requests (DoRequest):
- retries on network errors
- retries on
429and5xx - exponential backoff:
1s,2s,4s, ... capped at10s - max attempts controlled by
Config.MaxRetries(default3)
For streaming and multipart:
DoStreamRequest: no retryDoMultipartRequest: no automatic retry (reader may not be rewindable)
Context cancellation
All operations use context-aware requests. Canceling context interrupts in-flight operations. WebSocket connections are also closed on context cancellation.