UNPKG

hono-ban

Version:

HTTP-friendly error objects for Hono, inspired by Boom

41 lines (40 loc) 1.45 kB
/** * RFC 7807 Problem Details hooks for Hono applications * @module hono-ban/formatters/rfc7807/hooks */ import { Hook } from "@hono/zod-openapi"; import { Env } from "hono"; import type { RFC7807FormatterOptions as RFC7807Options, BanOptions } from "../../types"; /** * Create a Hono hook that formats validation errors using RFC 7807 * * This hook throws a badRequest error that will be caught and processed by the ban middleware. * You can provide options to override the default behavior of the middleware. * * @example * // Basic usage - inherits all settings from middleware * app.openapi(route, handler, { onError: createRFC7807Hook() }); * * @example * // With custom message * app.openapi(route, handler, { * onError: createRFC7807Hook({ message: "Custom validation error" }) * }); * * @example * // With custom formatter and sanitization * app.openapi(route, handler, { * onError: createRFC7807Hook({ * formatter: customFormatter, * sanitize: ['password', 'token'] * }) * }); */ export declare function createRFC7807Hook<E extends Env = Env>(options?: RFC7807Options & Partial<BanOptions>): Hook<any, E, any, any>; /** * Pre-configured RFC 7807 hook with default options * * This is a convenience export that uses the default options. * It will throw a badRequest error that will be caught and processed by the ban middleware. */ export declare const rfc7807Hook: Hook<any, Env, any, any>;