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');
ClassStatus
ValidationError400
Unauthorized401
Forbidden403
NotFound404
Conflict409
RateLimited429
InternalError, ConfigError500

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.