import { HTTPException } from "hono/http-exception";
import type { ContentfulStatusCode } from "hono/utils/http-status";
import type { ErrorResponse } from "@/models/errors";

export function createHTTPException<
	TContext extends Record<string, unknown> = Record<string, never>,
>(statusCode: ContentfulStatusCode, message: string, context?: TContext) {
	return new HTTPException(statusCode, {
		res: Response.json({
			error: {
				message,
				context: context ?? null,
			},
		} satisfies ErrorResponse),
	});
}
