SDK-specific error handling patterns with type safety and automatic recovery
The SDK provides consistent, type-safe error handling across all API operations with automatic recovery mechanisms and structured error responses.
All SDK methods return a consistent ApiResult<T>
structure:
The SDK provides structured error responses with consistent codes:
Authentication Errors
Automatically handled by SDK, but you can detect them:
Common Codes:
UNAUTHORIZED
- Invalid or expired tokenTOKEN_EXPIRED
- Token needs refresh (handled automatically)INVALID_CREDENTIALS
- Login failedValidation Errors
Field-specific validation failures:
Common Codes:
VALIDATION_ERROR
- Field validation failedINVALID_INPUT
- Malformed request dataCONSTRAINT_VIOLATION
- Business rule violationResource Errors
Missing or unavailable resources:
Common Codes:
NOT_FOUND
- Resource doesnβt existACCESS_DENIED
- Insufficient permissionsRESOURCE_CONFLICT
- Conflicting operationNetwork Errors
Connection and timeout issues:
Common Codes:
NETWORK_ERROR
- Connection failedTIMEOUT
- Request timed outUNAUTHORIZED
- Authentication failedThe SDK automatically handles token expiry:
The SDK automatically handles token refresh and authentication recovery:
Never assume SDK operations succeed - always check the success
field
Use error codes to provide appropriate user experiences for different failure scenarios
Provide graceful degradation when operations fail
Track error rates and patterns to identify issues early
The SDKβs error handling builds on top of the patterns described in the Storefront Guides, providing automatic recovery and type safety for a better developer experience.