@casoon/auditmysite
Version:
Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe
110 lines • 3.08 kB
JavaScript
;
/**
* Custom Error Classes for AuditMySite
* Provides type-safe error handling across the application
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnalysisError = exports.BrowserError = exports.ValidationError = exports.TimeoutError = exports.NetworkError = exports.AuditError = void 0;
exports.isAuditError = isAuditError;
exports.isError = isError;
exports.getErrorMessage = getErrorMessage;
exports.getErrorStack = getErrorStack;
exports.toAuditError = toAuditError;
class AuditError extends Error {
constructor(message, code, context) {
super(message);
this.code = code;
this.context = context;
this.name = 'AuditError';
Error.captureStackTrace(this, this.constructor);
}
}
exports.AuditError = AuditError;
class NetworkError extends AuditError {
constructor(message, context) {
super(message, 'NETWORK_ERROR', context);
this.name = 'NetworkError';
}
}
exports.NetworkError = NetworkError;
class TimeoutError extends AuditError {
constructor(message, context) {
super(message, 'TIMEOUT_ERROR', context);
this.name = 'TimeoutError';
}
}
exports.TimeoutError = TimeoutError;
class ValidationError extends AuditError {
constructor(message, context) {
super(message, 'VALIDATION_ERROR', context);
this.name = 'ValidationError';
}
}
exports.ValidationError = ValidationError;
class BrowserError extends AuditError {
constructor(message, context) {
super(message, 'BROWSER_ERROR', context);
this.name = 'BrowserError';
}
}
exports.BrowserError = BrowserError;
class AnalysisError extends AuditError {
constructor(message, context) {
super(message, 'ANALYSIS_ERROR', context);
this.name = 'AnalysisError';
}
}
exports.AnalysisError = AnalysisError;
/**
* Type guard to check if an error is an AuditError
*/
function isAuditError(error) {
return error instanceof AuditError;
}
/**
* Type guard to check if value is an Error
*/
function isError(error) {
return error instanceof Error;
}
/**
* Safe error message extraction
*/
function getErrorMessage(error) {
if (isError(error)) {
return error.message;
}
if (typeof error === 'string') {
return error;
}
if (error && typeof error === 'object' && 'message' in error) {
return String(error.message);
}
return 'Unknown error';
}
/**
* Safe error stack extraction
*/
function getErrorStack(error) {
if (isError(error)) {
return error.stack;
}
return undefined;
}
/**
* Convert unknown error to AuditError
*/
function toAuditError(error, code = 'UNKNOWN_ERROR', context) {
if (isAuditError(error)) {
return error;
}
const message = getErrorMessage(error);
const auditError = new AuditError(message, code, context);
// Preserve original stack if available
const stack = getErrorStack(error);
if (stack) {
auditError.stack = stack;
}
return auditError;
}
//# sourceMappingURL=errors.js.map