Errors
The error types Mongster uses for validation, queries, and runtime failures
All Mongster errors inherit from MongsterError. The specialized classes let you handle failures at the right level without pattern-matching raw strings.
import { , } from "mongster";
try {
throw new ("Email is required");
} catch () {
if ( instanceof ) {
.(.);
}
if ( instanceof ) {
.(., .);
}
}Error classes
| Error | Typical cause |
|---|---|
SchemaError | Invalid input for a schema field |
ValidationError | Invalid update operators or schema validation failure |
QueryError | Invalid query builder usage or populate / aggregation misuse |
ConnectionError | Missing URI or failed database connection |
TransactionError | A transaction callback failed or the session could not complete |
IndexSyncError | Index normalization or syncing failed |
When to catch what
- Catch
ValidationErrorwhen you want to return a user-facing input error. - Catch
ConnectionErrorduring startup and fail fast. - Catch
MongsterErrorwhen you want one fallback for every library-specific failure.