server/classes/errors/api-error.ts
2024-12-30 18:00:23 +01:00

25 lines
754 B
TypeScript

import type { ContentfulStatusCode } from "hono/utils/http-status";
import type { JSONObject } from "hono/utils/types";
/**
* API Error
*
* Custom error class used to throw errors in the API. Includes a status code, a message and an optional description.
* @extends Error
*/
export class ApiError extends Error {
/**
* @param {StatusCode} status - The status code of the error
* @param {string} message - The message of the error
* @param {string | JSONObject} [details] - The description of the error
*/
public constructor(
public status: ContentfulStatusCode,
public message: string,
public details?: string | JSONObject,
) {
super(message);
this.name = "ApiError";
}
}