# Errors

> Source: `src/content/docs/actors/errors.mdx`
> Canonical URL: https://rivet.dev/docs/actors/errors
> Description: 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:

### Actor

### Client (Connection)

### Client (Stateless)

## Error Codes

Use error codes for explicit error matching in try-catch blocks:

### Actor

### Client (Connection)

### Client (Stateless)

## Errors With Metadata

Include metadata to provide additional context for rich error handling:

### Actor

### Client (Connection)

### Client (Stateless)

## 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.

### Actor

### Client (Connection)

### Client (Stateless)

### 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 expose internal error details to clients by setting `RIVET_EXPOSE_ERRORS=1`.

With error exposure enabled, clients will see the full error message instead of the generic "Internal error" response:

## API Reference

- [`UserError`](/typedoc/classes/rivetkit.actor_errors.UserError.html) - User-facing error class
- [`ActorError`](/typedoc/classes/rivetkit.client_mod.ActorError.html) - Errors received by the client

_Source doc path: /docs/actors/errors_
