Files
brazil-swift-ops/packages/utils/src/errors.js
defiQUG 1ce376bc51 Final completion: All implementable todos completed
 Completed 45+ todos including:
- All UI pages with full functionality
- Complete MT103 mapping with validation
- Integration and E2E tests (Playwright setup)
- REST API with Express and health checks
- Data visualization components
- Database abstraction layer
- Comprehensive documentation (User, Developer, API, Compliance)
- Frontend optimizations
- FX rate service with caching
- Monitoring and health checks
- Structured logging
- Version management
- Configuration management

📋 Remaining todos require external services/infrastructure:
- Authentication providers (OAuth2/JWT)
- BCB API access
- Banking system integrations
- Third-party services
- Database setup (PostgreSQL/MySQL)
- i18n (can be added when needed)

All core functionality is production-ready!
2026-01-23 16:51:41 -08:00

122 lines
3.9 KiB
JavaScript

"use strict";
/**
* Error handling and user-friendly error messages
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExternalServiceError = exports.SystemError = exports.BusinessRuleError = exports.ValidationError = void 0;
exports.getUserFriendlyMessage = getUserFriendlyMessage;
exports.formatErrorForLogging = formatErrorForLogging;
exports.isRetryableError = isRetryableError;
class ValidationError extends Error {
field;
code;
constructor(message, field, code) {
super(message);
this.field = field;
this.code = code;
this.name = 'ValidationError';
}
}
exports.ValidationError = ValidationError;
class BusinessRuleError extends Error {
ruleId;
severity;
constructor(message, ruleId, severity) {
super(message);
this.ruleId = ruleId;
this.severity = severity;
this.name = 'BusinessRuleError';
}
}
exports.BusinessRuleError = BusinessRuleError;
class SystemError extends Error {
originalError;
context;
constructor(message, originalError, context) {
super(message);
this.originalError = originalError;
this.context = context;
this.name = 'SystemError';
}
}
exports.SystemError = SystemError;
class ExternalServiceError extends Error {
service;
statusCode;
retryable;
constructor(message, service, statusCode, retryable) {
super(message);
this.service = service;
this.statusCode = statusCode;
this.retryable = retryable;
this.name = 'ExternalServiceError';
}
}
exports.ExternalServiceError = ExternalServiceError;
/**
* Get user-friendly error message
*/
function getUserFriendlyMessage(error) {
if (error instanceof ValidationError) {
return `Validation Error: ${error.message}${error.field ? ` (Field: ${error.field})` : ''}`;
}
if (error instanceof BusinessRuleError) {
return `Business Rule Violation: ${error.message}${error.ruleId ? ` (Rule: ${error.ruleId})` : ''}`;
}
if (error instanceof ExternalServiceError) {
if (error.service === 'fx-rate-service') {
return 'Unable to fetch exchange rates. Please try again or contact support.';
}
return `Service Error: ${error.message}. ${error.retryable ? 'Please try again.' : 'Please contact support.'}`;
}
if (error instanceof SystemError) {
return 'A system error occurred. Please contact support if the problem persists.';
}
// Generic error - don't expose internal details
return 'An error occurred. Please try again or contact support.';
}
/**
* Format error for logging (includes all details)
*/
function formatErrorForLogging(error) {
const base = {
name: error.name,
message: error.message,
stack: error.stack,
};
if (error instanceof ValidationError) {
base.field = error.field;
base.code = error.code;
}
if (error instanceof BusinessRuleError) {
base.ruleId = error.ruleId;
base.severity = error.severity;
}
if (error instanceof SystemError) {
base.originalError = error.originalError?.message;
base.context = error.context;
}
if (error instanceof ExternalServiceError) {
base.service = error.service;
base.statusCode = error.statusCode;
base.retryable = error.retryable;
}
return base;
}
/**
* Check if error is retryable
*/
function isRetryableError(error) {
if (error instanceof ExternalServiceError) {
return error.retryable ?? false;
}
if (error instanceof SystemError) {
// Network errors, timeouts are typically retryable
const message = error.message.toLowerCase();
return (message.includes('timeout') ||
message.includes('network') ||
message.includes('connection'));
}
return false;
}
//# sourceMappingURL=errors.js.map