Docs / Errors
Errors
Throw HopakError subclasses — they serialize to clean JSON with a code.
Throw any HopakError subclass — it serializes to the right status with a clean JSON body. Unknown errors become 500 with a safe message.
Built-in errors
import { NotFound, Forbidden, Unauthorized, Conflict } from '@hopak/core';
throw new NotFound('Post not found');
throw new Forbidden('You are not the author');
throw new Unauthorized('Login required');
throw new Conflict('Email already in use');
| Class | Status |
|---|---|
ValidationError | 400 |
Unauthorized | 401 |
Forbidden | 403 |
NotFound | 404 |
Conflict | 409 |
RateLimited | 429 |
InternalError, ConfigError | 500 |
Custom errors
Custom errors extend HopakError:
import { HopakError } from '@hopak/core';
class PaymentFailed extends HopakError {
override readonly status = 402;
override readonly code = 'PAYMENT_FAILED';
}
Unknown errors (anything not HopakError) become 500 with a safe message; the original is logged.