import type { ErrorHandler } from "hono"; import type { HonoEnv } from "./types"; /** * Standardized API error class. * Throw this from any route handler — the errorHandler middleware * will format it into `{ error: { message, code, details? } }`. */ export declare class ApiError extends Error { readonly statusCode: number; readonly code: string; readonly details?: unknown; constructor(statusCode: number, code: string, message: string, details?: unknown); static badRequest(message: string, code?: string, details?: unknown): ApiError; static unauthorized(message: string, code?: string): ApiError; static forbidden(message: string, code?: string): ApiError; static notFound(message: string, code?: string): ApiError; static conflict(message: string, code?: string): ApiError; static internal(message: string, code?: string): ApiError; static serviceUnavailable(message: string, code?: string): ApiError; } /** * Canonical error response shape: * `{ error: { message: string, code: string, details?: unknown } }` */ export interface ErrorResponse { error: { message: string; code: string; details?: unknown; /** Request correlation ID for tracing (echoes X-Request-ID). */ requestId?: string; }; } /** * General shape of errors that flow through the API error handler. * Extends Error with optional HTTP status, error code, and details. */ export interface RebaseApiError extends Error { statusCode?: number; code?: string; details?: unknown; } /** * Type guard for errors that carry optional API metadata (statusCode, code, details). * Returns true for any Error instance — the optional properties are then * checked via normal property access. */ export declare function isRebaseApiError(error: unknown): error is RebaseApiError; /** * Hono error-handling middleware (`app.onError`). * Converts any error into the canonical `{ error: { message, code } }` shape. */ export declare const errorHandler: ErrorHandler;