The Go SDK returns all API errors asDocumentation Index
Fetch the complete documentation index at: https://docs.phala.com/llms.txt
Use this file to discover all available pages before exploring further.
*phala.APIError, which implements the error interface. This gives you a single type to handle, with helper methods to classify the error and decide what to do next.
This page covers how to catch and handle errors from the SDK. For the full list of ERR-xxxx error codes returned by the API, see the Error Codes Reference.
The APIError Type
Every non-2xx response from the API is wrapped in an*APIError. Use errors.As to extract it from the returned error.
APIError Fields
| Field | Type | Description |
|---|---|---|
StatusCode | int | HTTP status code |
Message | string | Human-readable error message |
ErrorCode | string | Structured error code (e.g., "ERR-01-001") |
Detail | any | Raw error detail from API |
Body | string | Raw response body |
Headers | http.Header | Response headers |
Details | []ErrorDetail | Field-level validation errors |
Suggestions | []string | Suggested fixes |
Links | []ErrorLink | Documentation links |
Error Classification
APIError provides boolean methods to classify errors by category. These make it easy to write switch-style error handling without checking status codes directly.
Classification Methods
| Method | Status Codes | Description |
|---|---|---|
IsAuth() | 401, 403 | Authentication or authorization failure |
IsValidation() | 422 | Request validation failure (field-level details in Details) |
IsBusiness() | 4xx (not auth/validation) | Business logic error |
IsServer() | 500+ | Server-side error |
IsRetryable() | 409, 429, 503 | Transient error worth retrying |
IsConflict() | 409 | Resource conflict |
IsComposePrecondition() | 465 | Compose hash precondition failure (requires on-chain confirmation) |
IsStructured() | any | Has a structured ErrorCode |
A 409 Conflict with a structured
ErrorCode is treated as a deterministic business error and is not retryable. Only bare 409 responses (without an error code) are retried automatically.Structured Errors
Some API errors include a structuredErrorCode (like ERR-01-001) along with detailed suggestions and documentation links. Check for these with IsStructured() or HasErrorCode().
HasErrorCode
Check for a specific error code:FormatError
TheFormatError method produces a human-readable string that includes the error code, message, field-level details, suggestions, and reference links.
Retry-After Header
When the API returns a 429 (Too Many Requests) or 503 (Service Unavailable), it may include aRetry-After header. The RetryAfter() method parses this into a time.Duration.
0 if the header is absent or unparseable.
Automatic Retries
The SDK automatically retries requests that fail with retryable status codes (409, 429, 503). Retries use exponential backoff starting at 1 second with a 20-second cap. Configure the maximum number of retries when creating the client.Validation Error Details
WhenIsValidation() is true, the Details field contains field-level error information.

