@phala/cloud SDK provides a structured error hierarchy and two error handling patterns: throwing (default) and safe (result-based).
This page covers how to catch and handle errors in the SDK. For the full list of ERR-xxxx error codes (returned by both the API and the CLI), see the Error Codes Reference.
Error Hierarchy
All API errors extendPhalaCloudError:
Catching Errors
Using instanceof
Using Discriminator Properties
Each error class has a boolean discriminator property:Error Classes
PhalaCloudError
Base class for all errors. Properties:ValidationError
Thrown on HTTP 422. Contains parsed field-level validation errors from FastAPI/Pydantic.
Each
ValidationErrorItem:
AuthError
Thrown on HTTP 401 or 403.BusinessError
Thrown on HTTP 400, 409, and other 4xx errors.ResourceError
ExtendsBusinessError. Thrown for structured errors with ERR-xxxx codes.
ServerError
Thrown on HTTP 500+.UnknownError
Thrown for network issues or unexpected errors.Safe Methods
Every action has asafe variant that returns SafeResult instead of throwing:
safe<ActionName>:
Formatting Utilities
formatValidationErrors(errors, options?)
Format validation errors for display:
formatErrorMessage(error, options?)
Format any PhalaCloudError for display:
formatStructuredError(error, options?)
Format ResourceError with codes, details, suggestions, and links:
Event-Based Error Handling
Listen to errors globally via the client event system:Related
- SDK Overview — getting started
- Error Codes Reference — full list of
ERR-xxxxcodes

