Error Handling
Learn how oss-ratelimit signals when a rate limit is exceeded and discover strategies for catching these errors and providing appropriate responses to your users.
Error Handling
oss-ratelimit throws specific errors and emits events.
Custom Error Types
RatelimitError: Base class for all library errors.RedisConnectionError: Thrown when connecting to or communicating with Redis fails (andfailOpenis false).RateLimitExceededError: Thrown byblock()if the rate limit is still exceeded after the max wait time. ContainsretryAfterandidentifier.
Handling Errors
Use try...catch blocks and check error types:
Nextjs Integration with Oss Ratelimit Redis
A step-by-step guide on how to seamlessly integrate oss-ratelimit using Redis as a storage backend within your Next.js application, including middleware examples.
Using Event Emitter
Leverage the built-in Node.js EventEmitter in oss-ratelimit to subscribe to events like 'limitReached' or 'error' for monitoring, logging, or custom logic.