@dawans/promptshield
Version:
Secure your LLM stack with enterprise-grade RulePacks for AI safety scanning
105 lines (104 loc) • 3.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemoryError = exports.TimeoutError = exports.ProcessingError = exports.ConfigurationError = exports.RuleExecutionError = exports.FileSystemError = exports.NotFoundError = exports.ValidationError = exports.DomainError = void 0;
/**
* Base class for domain errors
*/
class DomainError extends Error {
constructor(message, cause) {
super(message);
this.cause = cause;
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
}
exports.DomainError = DomainError;
/**
* Validation error
*/
class ValidationError extends DomainError {
constructor(message, errors = [], cause) {
super(message, cause);
this.errors = errors;
this.code = 'VALIDATION_ERROR';
this.statusCode = 400;
}
}
exports.ValidationError = ValidationError;
/**
* Not found error
*/
class NotFoundError extends DomainError {
constructor(resource, identifier, cause) {
super(`${resource} not found: ${identifier}`, cause);
this.code = 'NOT_FOUND';
this.statusCode = 404;
}
}
exports.NotFoundError = NotFoundError;
/**
* File system error
*/
class FileSystemError extends DomainError {
constructor(operation, path, cause) {
super(`File system error during ${operation}: ${path}`, cause);
this.code = 'FILE_SYSTEM_ERROR';
this.statusCode = 500;
}
}
exports.FileSystemError = FileSystemError;
/**
* Rule execution error
*/
class RuleExecutionError extends DomainError {
constructor(ruleId, message, cause) {
super(`Rule execution failed for ${ruleId}: ${message}`, cause);
this.code = 'RULE_EXECUTION_ERROR';
this.statusCode = 500;
}
}
exports.RuleExecutionError = RuleExecutionError;
/**
* Configuration error
*/
class ConfigurationError extends DomainError {
constructor(message, cause) {
super(`Configuration error: ${message}`, cause);
this.code = 'CONFIGURATION_ERROR';
this.statusCode = 400;
}
}
exports.ConfigurationError = ConfigurationError;
/**
* Processing error
*/
class ProcessingError extends DomainError {
constructor(message, cause) {
super(`Processing error: ${message}`, cause);
this.code = 'PROCESSING_ERROR';
this.statusCode = 500;
}
}
exports.ProcessingError = ProcessingError;
/**
* Timeout error
*/
class TimeoutError extends DomainError {
constructor(operation, timeoutSeconds, cause) {
super(`Operation ${operation} timed out after ${timeoutSeconds} seconds`, cause);
this.code = 'TIMEOUT_ERROR';
this.statusCode = 408;
}
}
exports.TimeoutError = TimeoutError;
/**
* Memory error
*/
class MemoryError extends DomainError {
constructor(threshold, current, cause) {
super(`Memory usage (${current}%) exceeded threshold (${threshold}%)`, cause);
this.code = 'MEMORY_ERROR';
this.statusCode = 507;
}
}
exports.MemoryError = MemoryError;