Overview
Most errors in our SDK are typed asConnectError
, providing structured error information
with specific error codes, metadata, and detailed messages. Our SDK uses a structured response
pattern that returns { error, data }
instead of throwing errors.
Basic Error Handling
ConnectError Properties
code
: The specific error code (see Error Codes below)message
: Full error message including status coderawMessage
: Error message without status code prefixmetadata
: Response headers and trailersdetails
: Additional error details for advanced use casescause
: Underlying cause of the error
Error Codes
Code | Value | Description |
---|---|---|
Canceled | 1 | Operation canceled by user |
Unknown | 2 | Unknown error |
InvalidArgument | 3 | Invalid argument regardless of state |
DeadlineExceeded | 4 | Operation expired |
NotFound | 5 | Entity not found |
AlreadyExists | 6 | Entity already exists |
PermissionDenied | 7 | Operation not authorized |
ResourceExhausted | 8 | Quota exhausted |
FailedPrecondition | 9 | Invalid argument in current state |
Aborted | 10 | Operation aborted |
OutOfRange | 11 | Out of bounds |
Unimplemented | 12 | Operation not implemented |
Internal | 13 | Internal server error |
Unavailable | 14 | Service unavailable |
DataLoss | 15 | Unrecoverable data loss |
Unauthenticated | 16 | Request not authenticated |
Pattern Matching
Handle specific error types by matching against error codes:Best Practices
- Always check for errors: Check the
error
field before processingdata
- Match specific codes: Handle common error scenarios like authentication and authorization
- Provide user-friendly messages: Use
rawMessage
for cleaner user-facing errors - Log full context: Include error code and metadata in logs for debugging
- Implement retry logic: For transient errors like
Unavailable
orDeadlineExceeded