Errors
Rivet provides robust error handling with security built in by default. Errors are handled differently based on whether they should be exposed to clients or kept private.
There are two types of errors:
- UserError: Thrown from actors and safely returned to clients with full details
- Internal errors: All other errors that are converted to a generic error message for security
Throwing and Catching Errors
UserError lets you throw custom errors that will be safely returned to the client.
Throw a UserError with just a message:
Error Codes
Use error codes for explicit error matching in try-catch blocks:
Errors With Metadata
Include metadata to provide additional context for rich error handling:
Internal Errors
All errors that are not UserError instances are automatically converted to a generic "internal error" response. This prevents accidentally leaking sensitive information like stack traces, database details, or internal system information.
The original error message and stack trace are logged server-side for debugging. Check your server logs to see the full error details.
API Reference
UserError- User-facing error classActorError- Errors received by the client