* Base class for all API exceptions. This class extends the built-in Error class and adds properties for HTTP status code and error code.
* @property {number} status - The HTTP status code for the exception.
* @property {string} code - The error code for the exception.
* // example exception implementation
* export class ApiNotFoundException extends ApiException {
public code = "NOT_FOUND"
* throw new ApiNotFoundException("User not found", "user", { id: "123" })
export abstract class ApiException extends Error {
// ==============================
// ==============================
* Represents an API conflict exception. This exception is thrown when a request conflicts with the current state of the resource.
* @property {number} status - The HTTP status code for the exception, which is 409.
* @property {string} code - The error code for the exception, which is "CONFLICT".
export class ApiConflictException extends ApiException {
* Represents an API forbidden exception. This exception is thrown when the server refuses to authorize the request.
* @property {number} status - The HTTP status code for the exception, which is 403.
* @property {string} code - The error code for the exception, which is "FORBIDDEN".
export class ApiForbiddenException extends ApiException {
public code = "FORBIDDEN"
* Represents an API internal server error exception. This exception is thrown when the server encounters an unexpected condition that prevents it from fulfilling the request.
* @property {number} status - The HTTP status code for the exception, which is 500.
* @property {string} code - The error code for the exception, which is "INTERNAL_SERVER_ERROR".
export class ApiInternalServerErrorException extends ApiException {
public code = "INTERNAL_SERVER_ERROR"
* Represents an API not found exception. This exception is thrown when the requested resource could not be found.
* @property {number} status - The HTTP status code for the exception, which is 404.
* @property {string} code - The error code for the exception, which is "NOT_FOUND".
export class ApiNotFoundException extends ApiException {
public code = "NOT_FOUND"
* Represents an API unauthorized exception. This exception is thrown when the request lacks valid authentication credentials for the target resource.
* @property {number} status - The HTTP status code for the exception, which is 401.
* @property {string} code - The error code for the exception, which is "UNAUTHORIZED".
* @param {string} message - The error message for the exception.
export class ApiUnauthorizedException extends ApiException {
public code = "UNAUTHORIZED"
* Represents an API unprocessable content exception. This exception is thrown when the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.
* @property {number} status - The HTTP status code for the exception, which is 422.
* @property {string} code - The error code for the exception, which is "UNPROCESSABLE_CONTENT".
* @property {(string | undefined)} on - The field or property that caused the error.
* @property {(Record<string, string> | undefined)} errors - A record of errors, where each key is the field or property name and the value is the error message.
* @param {string} message - The error message for the exception.
* @param {(string | undefined)} on - The field or property that caused the error.
* @param {(Record<string, string> | undefined)} errors - A record of errors.
export class ApiUnprocessableContentException extends ApiException {
public code = "UNPROCESSABLE_CONTENT"
public errors?: Record<string, string>
constructor(message: string, on?: string, errors?: Record<string, string>) {