import { NextFunction, Request, Response } from "express"; import { Schema } from "mongoose"; export interface APIErrorConstructor { title: string; fields?: { [id: string]: string; }; id?: string; links?: { about?: string; type?: string; } | undefined; status?: number; code?: string; detail?: string; source?: { pointer?: string; parameter?: string; header?: string; }; meta?: { [id: string]: string; }; error?: Error; disableExternalErrorTracking?: boolean; } /** * APIError is a simple way to throw an error in an API route and control what is shown and the * HTTP code displayed. It follows the JSONAPI spec to standardize the fields, * allowing the UI to show more consistent, better error messages. * * ```ts * throw new APIError({ * title: "Only an admin can update that!", * status: 403, * code: "update-admin-error", * detail: "You must be an admin to change that field" * }); * ``` */ export declare class APIError extends Error { title: string; id: string | undefined; links: { about?: string; type?: string; } | undefined; status: number; code: string | undefined; detail: string | undefined; source: { pointer?: string; parameter?: string; header?: string; } | undefined; meta: { [id: string]: any; } | undefined; error?: Error; disableExternalErrorTracking?: boolean; constructor(data: APIErrorConstructor); } export declare const ErrorSchema: Schema, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, { title: string; id?: string | null | undefined; links?: string | null | undefined; status?: number | null | undefined; code?: string | null | undefined; detail?: string | null | undefined; source?: { pointer?: string | null | undefined; parameter?: string | null | undefined; header?: string | null | undefined; } | null | undefined; meta?: any; }, import("mongoose").Document> & import("mongoose").FlatRecord<{ title: string; id?: string | null | undefined; links?: string | null | undefined; status?: number | null | undefined; code?: string | null | undefined; detail?: string | null | undefined; source?: { pointer?: string | null | undefined; parameter?: string | null | undefined; header?: string | null | undefined; } | null | undefined; meta?: any; }> & { _id: import("mongoose").Types.ObjectId; } & { __v: number; }>; export declare function errorsPlugin(schema: Schema): void; export declare function isAPIError(error: Error): error is APIError; /** * Safely extracts the disableExternalErrorTracking property from an error. * Works with both APIError instances and regular Error objects that may have * this property attached. */ export declare function getDisableExternalErrorTracking(error: unknown): boolean | undefined; export declare function getAPIErrorBody(error: APIError): { [id: string]: any; }; export declare function apiUnauthorizedMiddleware(err: Error, _req: Request, res: Response, next: NextFunction): void; export declare function apiErrorMiddleware(err: Error, _req: Request, res: Response, next: NextFunction): void;