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.
Server-Side Logging
All internal errors are logged server-side with full details. When an internal error occurs, the complete error message, stack trace, and context are written to your server logs. This is where you should look first when debugging internal errors in production.
The client receives only a generic "Internal error" message for security, but you can find the full error details in your server logs including:
- Complete error message
- Stack trace
- Request context (actor ID, action name, connection ID, etc.)
- Timestamp
Always check your server logs to see the actual error details when debugging internal errors.
Exposing Errors to Clients (Development Only)
Warning: Only enable error exposure in development environments. In production, this will leak sensitive internal details to clients.
For faster debugging during development, you can automatically expose internal error details to clients. This is enabled when:
NODE_ENV=development- Automatically enabled in development modeRIVET_EXPOSE_ERRORS=1- Explicitly enable error exposure
With error exposure enabled, clients will see the full error message instead of the generic "Internal error" response:
API Reference
UserError- User-facing error classActorError- Errors received by the client