Skip to content

v0.22.0 — self-handling exceptions + error codes

Choose a tag to compare

@tshafer tshafer released this 10 Jul 20:55
· 146 commits to main since this release

Richer exception handling:

export class PaymentRequiredException extends HttpException {
  code = "E_PAYMENT_REQUIRED";
  constructor() { super(402, "Payment required"); }
  handle(c) { return c.json({ error: this.message, upgrade: "/billing" }, this.status); }
  report() { metrics.increment("payment_required"); }
}
  • handle(c) → the exception renders itself.
  • report() → awaited before rendering, for logging/metrics (never masks the error).
  • code → included in the JSON error body. See docs/errors.md.