Skip to main content

Overview

The Upstash Redis SDK provides specific error types to help you handle different failure scenarios. All errors extend the standard JavaScript Error class with additional context.

Error Types

The SDK defines three main error types in pkg/error.ts:

UpstashError

The base error class for general Redis operation failures:
When it’s thrown:
  • Invalid Redis commands
  • Server-side errors
  • Invalid responses from Redis
  • Pipeline/transaction failures
Example:

UrlError

Thrown when an invalid URL is provided during client initialization:
When it’s thrown:
  • URL doesn’t start with https://
  • Malformed URL format
Example:

UpstashJSONParseError

Thrown when the SDK fails to parse a response from Redis:
When it’s thrown:
  • Response body is not valid JSON
  • Corrupted response data
  • Unexpected response format
Example:

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

Use keepErrors 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 the cause option for error chaining:
Access the cause:

Debugging Tips

1. Enable Latency Logging

2. Inspect Error Objects

3. Test Error Scenarios

See Also