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.
49 lines (48 loc) • 1.83 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base_exception_1 = __importDefault(require("./base.exception"));
/**
* @fileoverview Unprocessable Entity exception (HTTP 422)
* @author dr. Salmi <reevosolutions@gmail.com>
*/
/**
* Exception thrown when the request is well-formed but contains semantic errors.
* Corresponds to HTTP 422 Unprocessable Entity status code.
*
* @class UnprocessableEntityException
* @extends {BaseException}
* @example
* ```typescript
* throw new UnprocessableEntityException('Invalid data format');
* throw new UnprocessableEntityException('Business rule violation', {
* email: { value: 'test@test.com', message: 'Email already exists' }
* });
* ```
*/
class UnprocessableEntityException extends base_exception_1.default {
/**
* Creates an instance of UnprocessableEntityException.
*
* @param {string} [message='Unprocessable Entity'] - The error message
* @param {ErrorFields} [fields={}] - Field-specific errors
* @param {Record<string, any>} [context] - Additional context
* @memberof UnprocessableEntityException
*/
constructor(message = 'Unprocessable Entity', fields = {}, context) {
super(message, 422, context);
this.fields = fields;
}
/**
* Returns a JSON representation of the unprocessable entity exception
*
* @returns {object} JSON representation including field errors
* @memberof UnprocessableEntityException
*/
toJSON() {
return Object.assign(Object.assign({}, super.toJSON()), { name: this.constructor.name, fields: this.fields });
}
}
exports.default = UnprocessableEntityException;
;