Overview
The Upstash Redis SDK provides specific error types to help you handle different failure scenarios. All errors extend the standard JavaScriptError class with additional context.
Error Types
The SDK defines three main error types inpkg/error.ts:
UpstashError
The base error class for general Redis operation failures:- Invalid Redis commands
- Server-side errors
- Invalid responses from Redis
- Pipeline/transaction failures
UrlError
Thrown when an invalid URL is provided during client initialization:- URL doesn’t start with
https:// - Malformed URL format
UpstashJSONParseError
Thrown when the SDK fails to parse a response from Redis:- Response body is not valid JSON
- Corrupted response data
- Unexpected response format
Common Error Scenarios
Type Mismatch Errors
Attempting an operation on the wrong data type:Authentication Errors
Network Errors
Pipeline Errors
By default, pipeline errors cause the entire pipeline to fail:Handling Pipeline Errors Individually
UsekeepErrors to handle errors per-command:
Best Practices
1. Use Type Guards
2. Implement Retry Logic
3. Graceful Degradation
4. Transaction Error Handling
5. Validation Before Operations
6. Logging and Monitoring
Error Cause Chain
Upstash errors support thecause option for error chaining: