UNPKG

jsm-exceptions

Version:

A comprehensive TypeScript exception library with HTTP status code support, detailed JSDoc documentation, and backward compatibility. Provides structured error handling for web applications and APIs.

64 lines (63 loc) 2.07 kB
import Joi from "joi"; import BaseException from "./base.exception"; /** * @fileoverview Validation exception (HTTP 422) * @author dr. Salmi <reevosolutions@gmail.com> */ /** * Exception thrown when input validation fails. * Corresponds to HTTP 422 Unprocessable Entity status code. * Supports both Joi validation errors and custom field errors. * * @class ValidationException * @extends {BaseException} * @example * ```typescript * // With custom field errors * throw new ValidationException('Validation failed', { * email: { value: 'invalid-email', message: 'Email format is invalid' } * }); * * // With Joi validation error * throw new ValidationException('Validation failed', joiValidationError); * ``` */ declare class ValidationException extends BaseException { /** * Field-specific validation errors * @type {ErrorFields} */ readonly fields: ErrorFields; /** * Indicates if this exception was created from a Joi validation error * @type {boolean} */ readonly isJoi: boolean; /** * Indicates if this exception was created from a Mongoose validation error * @type {boolean} */ readonly isMongoose: boolean; /** * Indicates if this exception was created from a Celebrate validation error * @type {boolean} */ readonly isCelebrate: boolean; /** * Creates an instance of ValidationException. * * @param {string} [message='Validation failed'] - The error message * @param {ErrorFields | Joi.ValidationError} [fields={}] - Field errors or Joi validation error * @param {Record<string, any>} [context] - Additional context * @memberof ValidationException */ constructor(message?: string, fields?: ErrorFields | Joi.ValidationError, context?: Record<string, any>); /** * Returns a JSON representation of the validation exception * * @returns {object} JSON representation including field errors * @memberof ValidationException */ toJSON(): object; } export default ValidationException;