UNPKG

@ingeze/api-error

Version:

A TypeScript library for handling HTTP errors in Express, NestJS, and Fastify APIs.

218 lines 6.33 kB
/** * Defines custom error classes for handling various "not found" scenarios (HTTP 404). * * Each class extends `NotFoundError`, which itself extends `ErrorHandler`. * These errors represent specific resource-not-found cases and provide * descriptive messages and error types for easier error handling and debugging. * * @module errors/not-found-error */ import type { NotFoundErrorType } from '../types/index.js'; import { ErrorHandler } from './error-handler.js'; /** * Represents a generic "Not Found" error corresponding to HTTP status 404. * * This error can be instantiated in two ways: * 1. By passing an optional `details` object with additional error information. * In this case, the error message defaults to "Resource not found". * 2. By passing a custom message string, an optional error type, and optional details. * * @extends ErrorHandler * * Response example: * ```json * { * "success": false, * "message": "Resource not found", * "statusCode": 404, * "type": "NOT_FOUND", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional error context, set by the user when throwing the error. */ export declare class NotFoundError extends ErrorHandler { constructor(details?: Record<string, unknown>); constructor(message?: string, type?: NotFoundErrorType, details?: Record<string, unknown>); } /** * Error thrown when a specific user is not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "User not found", * "statusCode": 404, * "type": "NOT_FOUND_USER", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the user not found, set by the user. */ export declare class UserNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } /** * Error for email not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "Email not found", * "statusCode": 404, * "type": "NOT_FOUND_EMAIL", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the email not found, set by the user. */ export declare class EmailNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } /** * Error for product not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "Product not found", * "statusCode": 404, * "type": "NOT_FOUND_PRODUCT", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the product not found, set by the user. */ export declare class ProductNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } /** * Error for post not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "Post not found", * "statusCode": 404, * "type": "NOT_FOUND_POST", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the post not found, set by the user. */ export declare class PostNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } /** * Error for comment not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "Comment not found", * "statusCode": 404, * "type": "NOT_FOUND_COMMENT", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the comment not found, set by the user. */ export declare class CommentNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } /** * Error for category not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "Category not found", * "statusCode": 404, * "type": "NOT_FOUND_CATEGORY", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the category not found, set by the user. */ export declare class CategoryNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } /** * Error for file not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "File not found", * "statusCode": 404, * "type": "NOT_FOUND_FILE", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the file not found, set by the user. */ export declare class FileNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } /** * Error for image not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "Image not found", * "statusCode": 404, * "type": "NOT_FOUND_IMAGE", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the image not found, set by the user. */ export declare class ImageNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } /** * Error for address not found. * * @extends NotFoundError * * Response example: * ```json * { * "success": false, * "message": "Address not found", * "statusCode": 404, * "type": "NOT_FOUND_ADDRESS", * "details": {} // Optional, provided by the user with extra error context * } * ``` * - `details`: Optional object with additional information about the address not found, set by the user. */ export declare class AddressNotFoundError extends NotFoundError { constructor(details?: Record<string, unknown>); } //# sourceMappingURL=not-found-error.d.ts.map