UNPKG

@chenhongqiao/fastify-http-errors-enhanced

Version:

A error handling plugin for Fastify that uses enhanced HTTP errors.

35 lines (34 loc) 1.23 kB
/// <reference types="node" /> import Ajv, { ValidateFunction } from 'ajv'; import { FastifyError } from 'fastify'; export declare const kHttpErrorsEnhancedConfiguration: unique symbol; export declare const kHttpErrorsEnhancedResponseValidations: unique symbol; export interface Configuration { hideUnhandledErrors?: boolean; convertValidationErrors?: boolean; allowUndeclaredResponses?: boolean; responseValidatorCustomizer?: (ajv: Ajv) => void; preHandler?: (error: FastifyError | Error) => Error; } declare module 'fastify' { interface FastifyInstance { [kHttpErrorsEnhancedResponseValidations]: [FastifyInstance, ResponseSchemas, [string, object][]][]; } interface FastifyRequest { [kHttpErrorsEnhancedConfiguration]?: Configuration; } } export interface GenericObject { [key: string]: any; } export type NodeError = NodeJS.ErrnoException; export type RequestSection = 'params' | 'query' | 'querystring' | 'headers' | 'body' | 'response'; export interface ResponseSchemas { [key: string]: ValidateFunction; } export interface Validations { [key: string]: { [key: string]: string; }; } export type ValidationFormatter = (...args: any[]) => string;