@serve.zone/dcrouter 11.14.0 → 11.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_serve/bundle.js +5 -9
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/cache/classes.cache.cleaner.d.ts +47 -0
- package/dist_ts/cache/classes.cache.cleaner.js +130 -0
- package/dist_ts/cache/classes.cached.document.d.ts +76 -0
- package/dist_ts/cache/classes.cached.document.js +100 -0
- package/dist_ts/cache/classes.cachedb.d.ts +60 -0
- package/dist_ts/cache/classes.cachedb.js +126 -0
- package/dist_ts/cache/documents/classes.cached.email.d.ts +125 -0
- package/dist_ts/cache/documents/classes.cached.email.js +337 -0
- package/dist_ts/cache/documents/classes.cached.ip.reputation.d.ts +119 -0
- package/dist_ts/cache/documents/classes.cached.ip.reputation.js +323 -0
- package/dist_ts/cache/documents/index.d.ts +2 -0
- package/dist_ts/cache/documents/index.js +3 -0
- package/dist_ts/cache/index.d.ts +4 -0
- package/dist_ts/cache/index.js +7 -0
- package/dist_ts/classes.cert-provision-scheduler.d.ts +54 -0
- package/dist_ts/classes.cert-provision-scheduler.js +118 -0
- package/dist_ts/classes.dcrouter.d.ts +399 -0
- package/dist_ts/classes.dcrouter.js +1697 -0
- package/dist_ts/classes.storage-cert-manager.d.ts +18 -0
- package/dist_ts/classes.storage-cert-manager.js +43 -0
- package/dist_ts/config/classes.api-token-manager.d.ts +46 -0
- package/dist_ts/config/classes.api-token-manager.js +150 -0
- package/dist_ts/config/classes.route-config-manager.d.ts +38 -0
- package/dist_ts/config/classes.route-config-manager.js +257 -0
- package/dist_ts/config/index.d.ts +3 -0
- package/dist_ts/config/index.js +5 -0
- package/dist_ts/config/validator.d.ts +104 -0
- package/dist_ts/config/validator.js +152 -0
- package/dist_ts/errors/base.errors.d.ts +224 -0
- package/dist_ts/errors/base.errors.js +320 -0
- package/dist_ts/errors/error-handler.d.ts +98 -0
- package/dist_ts/errors/error-handler.js +282 -0
- package/dist_ts/errors/error.codes.d.ts +115 -0
- package/dist_ts/errors/error.codes.js +136 -0
- package/dist_ts/errors/index.d.ts +54 -0
- package/dist_ts/errors/index.js +136 -0
- package/dist_ts/errors/reputation.errors.d.ts +183 -0
- package/dist_ts/errors/reputation.errors.js +292 -0
- package/dist_ts/http3/http3-route-augmentation.d.ts +50 -0
- package/dist_ts/http3/http3-route-augmentation.js +98 -0
- package/dist_ts/http3/index.d.ts +1 -0
- package/dist_ts/http3/index.js +2 -0
- package/dist_ts/index.d.ts +8 -0
- package/dist_ts/index.js +29 -0
- package/dist_ts/logger.d.ts +21 -0
- package/dist_ts/logger.js +81 -0
- package/dist_ts/monitoring/classes.metricscache.d.ts +32 -0
- package/dist_ts/monitoring/classes.metricscache.js +63 -0
- package/dist_ts/monitoring/classes.metricsmanager.d.ts +184 -0
- package/dist_ts/monitoring/classes.metricsmanager.js +744 -0
- package/dist_ts/monitoring/index.d.ts +1 -0
- package/dist_ts/monitoring/index.js +2 -0
- package/dist_ts/opsserver/classes.opsserver.d.ts +38 -0
- package/dist_ts/opsserver/classes.opsserver.js +87 -0
- package/dist_ts/opsserver/handlers/admin.handler.d.ts +31 -0
- package/dist_ts/opsserver/handlers/admin.handler.js +180 -0
- package/dist_ts/opsserver/handlers/api-token.handler.d.ts +6 -0
- package/dist_ts/opsserver/handlers/api-token.handler.js +62 -0
- package/dist_ts/opsserver/handlers/certificate.handler.d.ts +32 -0
- package/dist_ts/opsserver/handlers/certificate.handler.js +421 -0
- package/dist_ts/opsserver/handlers/config.handler.d.ts +7 -0
- package/dist_ts/opsserver/handlers/config.handler.js +192 -0
- package/dist_ts/opsserver/handlers/email-ops.handler.d.ts +30 -0
- package/dist_ts/opsserver/handlers/email-ops.handler.js +227 -0
- package/dist_ts/opsserver/handlers/index.d.ts +12 -0
- package/dist_ts/opsserver/handlers/index.js +13 -0
- package/dist_ts/opsserver/handlers/logs.handler.d.ts +25 -0
- package/dist_ts/opsserver/handlers/logs.handler.js +256 -0
- package/dist_ts/opsserver/handlers/radius.handler.d.ts +6 -0
- package/dist_ts/opsserver/handlers/radius.handler.js +295 -0
- package/dist_ts/opsserver/handlers/remoteingress.handler.d.ts +6 -0
- package/dist_ts/opsserver/handlers/remoteingress.handler.js +156 -0
- package/dist_ts/opsserver/handlers/route-management.handler.d.ts +14 -0
- package/dist_ts/opsserver/handlers/route-management.handler.js +117 -0
- package/dist_ts/opsserver/handlers/security.handler.d.ts +9 -0
- package/dist_ts/opsserver/handlers/security.handler.js +233 -0
- package/dist_ts/opsserver/handlers/stats.handler.d.ts +11 -0
- package/dist_ts/opsserver/handlers/stats.handler.js +403 -0
- package/dist_ts/opsserver/handlers/vpn.handler.d.ts +6 -0
- package/dist_ts/opsserver/handlers/vpn.handler.js +197 -0
- package/dist_ts/opsserver/helpers/guards.d.ts +27 -0
- package/dist_ts/opsserver/helpers/guards.js +43 -0
- package/dist_ts/opsserver/index.d.ts +1 -0
- package/dist_ts/opsserver/index.js +2 -0
- package/dist_ts/paths.d.ts +26 -0
- package/dist_ts/paths.js +45 -0
- package/dist_ts/plugins.d.ts +81 -0
- package/dist_ts/plugins.js +115 -0
- package/dist_ts/radius/classes.accounting.manager.d.ts +231 -0
- package/dist_ts/radius/classes.accounting.manager.js +462 -0
- package/dist_ts/radius/classes.radius.server.d.ts +171 -0
- package/dist_ts/radius/classes.radius.server.js +386 -0
- package/dist_ts/radius/classes.vlan.manager.d.ts +128 -0
- package/dist_ts/radius/classes.vlan.manager.js +279 -0
- package/dist_ts/radius/index.d.ts +13 -0
- package/dist_ts/radius/index.js +14 -0
- package/dist_ts/remoteingress/classes.remoteingress-manager.d.ts +94 -0
- package/dist_ts/remoteingress/classes.remoteingress-manager.js +271 -0
- package/dist_ts/remoteingress/classes.tunnel-manager.d.ts +59 -0
- package/dist_ts/remoteingress/classes.tunnel-manager.js +165 -0
- package/dist_ts/remoteingress/index.d.ts +2 -0
- package/dist_ts/remoteingress/index.js +3 -0
- package/dist_ts/security/classes.contentscanner.d.ts +164 -0
- package/dist_ts/security/classes.contentscanner.js +642 -0
- package/dist_ts/security/classes.ipreputationchecker.d.ts +160 -0
- package/dist_ts/security/classes.ipreputationchecker.js +537 -0
- package/dist_ts/security/classes.securitylogger.d.ts +144 -0
- package/dist_ts/security/classes.securitylogger.js +235 -0
- package/dist_ts/security/index.d.ts +3 -0
- package/dist_ts/security/index.js +4 -0
- package/dist_ts/sms/classes.smsservice.d.ts +15 -0
- package/dist_ts/sms/classes.smsservice.js +72 -0
- package/dist_ts/sms/config/sms.config.d.ts +93 -0
- package/dist_ts/sms/config/sms.config.js +2 -0
- package/dist_ts/sms/config/sms.schema.d.ts +5 -0
- package/dist_ts/sms/config/sms.schema.js +121 -0
- package/dist_ts/sms/index.d.ts +1 -0
- package/dist_ts/sms/index.js +2 -0
- package/dist_ts/storage/classes.storagemanager.d.ts +83 -0
- package/dist_ts/storage/classes.storagemanager.js +348 -0
- package/dist_ts/storage/index.d.ts +1 -0
- package/dist_ts/storage/index.js +3 -0
- package/dist_ts/vpn/classes.vpn-manager.d.ts +129 -0
- package/dist_ts/vpn/classes.vpn-manager.js +329 -0
- package/dist_ts/vpn/index.d.ts +1 -0
- package/dist_ts/vpn/index.js +2 -0
- package/dist_ts_apiclient/classes.apitoken.d.ts +41 -0
- package/dist_ts_apiclient/classes.apitoken.js +115 -0
- package/dist_ts_apiclient/classes.certificate.d.ts +57 -0
- package/dist_ts_apiclient/classes.certificate.js +69 -0
- package/dist_ts_apiclient/classes.config.d.ts +7 -0
- package/dist_ts_apiclient/classes.config.js +11 -0
- package/dist_ts_apiclient/classes.dcrouterapiclient.d.ts +41 -0
- package/dist_ts_apiclient/classes.dcrouterapiclient.js +81 -0
- package/dist_ts_apiclient/classes.email.d.ts +30 -0
- package/dist_ts_apiclient/classes.email.js +52 -0
- package/dist_ts_apiclient/classes.logs.d.ts +21 -0
- package/dist_ts_apiclient/classes.logs.js +14 -0
- package/dist_ts_apiclient/classes.radius.d.ts +59 -0
- package/dist_ts_apiclient/classes.radius.js +95 -0
- package/dist_ts_apiclient/classes.remoteingress.d.ts +54 -0
- package/dist_ts_apiclient/classes.remoteingress.js +136 -0
- package/dist_ts_apiclient/classes.route.d.ts +42 -0
- package/dist_ts_apiclient/classes.route.js +154 -0
- package/dist_ts_apiclient/classes.stats.d.ts +47 -0
- package/dist_ts_apiclient/classes.stats.js +38 -0
- package/dist_ts_apiclient/index.d.ts +10 -0
- package/dist_ts_apiclient/index.js +14 -0
- package/dist_ts_apiclient/plugins.d.ts +3 -0
- package/dist_ts_apiclient/plugins.js +5 -0
- package/dist_ts_interfaces/data/remoteingress.d.ts +2 -0
- package/dist_ts_interfaces/data/vpn.d.ts +1 -2
- package/dist_ts_interfaces/requests/vpn.d.ts +1 -1
- package/dist_ts_web/00_commitinfo_data.d.ts +8 -0
- package/dist_ts_web/00_commitinfo_data.js +9 -0
- package/dist_ts_web/appstate.d.ts +238 -0
- package/dist_ts_web/appstate.js +1174 -0
- package/dist_ts_web/elements/index.d.ts +13 -0
- package/dist_ts_web/elements/index.js +14 -0
- package/dist_ts_web/elements/ops-dashboard.d.ts +23 -0
- package/dist_ts_web/elements/ops-dashboard.js +323 -0
- package/dist_ts_web/elements/ops-view-apitokens.d.ts +13 -0
- package/dist_ts_web/elements/ops-view-apitokens.js +371 -0
- package/dist_ts_web/elements/ops-view-certificates.d.ts +22 -0
- package/dist_ts_web/elements/ops-view-certificates.js +528 -0
- package/dist_ts_web/elements/ops-view-config.d.ts +19 -0
- package/dist_ts_web/elements/ops-view-config.js +339 -0
- package/dist_ts_web/elements/ops-view-emails.d.ts +21 -0
- package/dist_ts_web/elements/ops-view-emails.js +165 -0
- package/dist_ts_web/elements/ops-view-logs.d.ts +13 -0
- package/dist_ts_web/elements/ops-view-logs.js +159 -0
- package/dist_ts_web/elements/ops-view-network.d.ts +71 -0
- package/dist_ts_web/elements/ops-view-network.js +764 -0
- package/dist_ts_web/elements/ops-view-overview.d.ts +22 -0
- package/dist_ts_web/elements/ops-view-overview.js +456 -0
- package/dist_ts_web/elements/ops-view-remoteingress.d.ts +20 -0
- package/dist_ts_web/elements/ops-view-remoteingress.js +494 -0
- package/dist_ts_web/elements/ops-view-routes.d.ts +12 -0
- package/dist_ts_web/elements/ops-view-routes.js +404 -0
- package/dist_ts_web/elements/ops-view-security.d.ts +21 -0
- package/dist_ts_web/elements/ops-view-security.js +574 -0
- package/dist_ts_web/elements/ops-view-vpn.d.ts +14 -0
- package/dist_ts_web/elements/ops-view-vpn.js +365 -0
- package/dist_ts_web/elements/shared/css.d.ts +1 -0
- package/dist_ts_web/elements/shared/css.js +10 -0
- package/dist_ts_web/elements/shared/index.d.ts +2 -0
- package/dist_ts_web/elements/shared/index.js +3 -0
- package/dist_ts_web/elements/shared/ops-sectionheading.d.ts +5 -0
- package/dist_ts_web/elements/shared/ops-sectionheading.js +82 -0
- package/dist_ts_web/index.d.ts +1 -0
- package/dist_ts_web/index.js +10 -0
- package/dist_ts_web/plugins.d.ts +6 -0
- package/dist_ts_web/plugins.js +11 -0
- package/dist_ts_web/router.d.ts +19 -0
- package/dist_ts_web/router.js +91 -0
- package/package.json +2 -2
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.dcrouter.ts +51 -20
- package/ts/config/classes.route-config-manager.ts +7 -6
- package/ts/opsserver/handlers/vpn.handler.ts +3 -5
- package/ts/vpn/classes.vpn-manager.ts +68 -19
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/appstate.ts +2 -2
- package/ts_web/elements/ops-view-vpn.ts +5 -9
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { ErrorSeverity, ErrorCategory, ErrorRecoverability } from './error.codes.js';
|
|
2
|
+
import { logger } from '../logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base class for all errors in the Platform Service
|
|
5
|
+
* Adds structured error information, logging, and error tracking
|
|
6
|
+
*/
|
|
7
|
+
export class PlatformError extends Error {
|
|
8
|
+
/** Error code identifying the specific error type */
|
|
9
|
+
code;
|
|
10
|
+
/** Error severity level */
|
|
11
|
+
severity;
|
|
12
|
+
/** Error category for grouping related errors */
|
|
13
|
+
category;
|
|
14
|
+
/** Whether the error can be recovered from automatically */
|
|
15
|
+
recoverability;
|
|
16
|
+
/** Additional context information */
|
|
17
|
+
context;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new PlatformError
|
|
20
|
+
*
|
|
21
|
+
* @param message Error message
|
|
22
|
+
* @param code Error code from error.codes.ts
|
|
23
|
+
* @param severity Error severity level
|
|
24
|
+
* @param category Error category
|
|
25
|
+
* @param recoverability Error recoverability indication
|
|
26
|
+
* @param context Additional context information
|
|
27
|
+
*/
|
|
28
|
+
constructor(message, code, severity = ErrorSeverity.MEDIUM, category = ErrorCategory.OTHER, recoverability = ErrorRecoverability.NON_RECOVERABLE, context = {}) {
|
|
29
|
+
super(message);
|
|
30
|
+
// Set error metadata
|
|
31
|
+
this.name = this.constructor.name;
|
|
32
|
+
this.code = code;
|
|
33
|
+
this.severity = severity;
|
|
34
|
+
this.category = category;
|
|
35
|
+
this.recoverability = recoverability;
|
|
36
|
+
// Add timestamp if not provided
|
|
37
|
+
this.context = {
|
|
38
|
+
...context,
|
|
39
|
+
timestamp: context.timestamp || Date.now(),
|
|
40
|
+
};
|
|
41
|
+
// Capture stack trace
|
|
42
|
+
Error.captureStackTrace(this, this.constructor);
|
|
43
|
+
// Log the error automatically unless explicitly disabled
|
|
44
|
+
if (!context.data?.skipLogging) {
|
|
45
|
+
this.logError();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Logs the error using the platform logger
|
|
50
|
+
*/
|
|
51
|
+
logError() {
|
|
52
|
+
const logLevel = this.getLogLevelFromSeverity();
|
|
53
|
+
// Construct structured log entry
|
|
54
|
+
const logData = {
|
|
55
|
+
error_code: this.code,
|
|
56
|
+
error_name: this.name,
|
|
57
|
+
severity: this.severity,
|
|
58
|
+
category: this.category,
|
|
59
|
+
recoverability: this.recoverability,
|
|
60
|
+
...this.context
|
|
61
|
+
};
|
|
62
|
+
// Log with appropriate level
|
|
63
|
+
logger.log(logLevel, this.message, logData);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Maps severity levels to log levels
|
|
67
|
+
*/
|
|
68
|
+
getLogLevelFromSeverity() {
|
|
69
|
+
switch (this.severity) {
|
|
70
|
+
case ErrorSeverity.CRITICAL:
|
|
71
|
+
case ErrorSeverity.HIGH:
|
|
72
|
+
return 'error';
|
|
73
|
+
case ErrorSeverity.MEDIUM:
|
|
74
|
+
return 'warn';
|
|
75
|
+
case ErrorSeverity.LOW:
|
|
76
|
+
return 'info';
|
|
77
|
+
case ErrorSeverity.INFO:
|
|
78
|
+
return 'debug';
|
|
79
|
+
default:
|
|
80
|
+
return 'error';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns a JSON representation of the error
|
|
85
|
+
*/
|
|
86
|
+
toJSON() {
|
|
87
|
+
return {
|
|
88
|
+
name: this.name,
|
|
89
|
+
message: this.message,
|
|
90
|
+
code: this.code,
|
|
91
|
+
severity: this.severity,
|
|
92
|
+
category: this.category,
|
|
93
|
+
recoverability: this.recoverability,
|
|
94
|
+
context: this.context,
|
|
95
|
+
stack: process.env.NODE_ENV !== 'production' ? this.stack : undefined
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates an instance with retry information
|
|
100
|
+
*
|
|
101
|
+
* @param maxRetries Maximum number of retries
|
|
102
|
+
* @param currentRetry Current retry count
|
|
103
|
+
* @param retryDelay Delay between retries in ms
|
|
104
|
+
*/
|
|
105
|
+
withRetry(maxRetries, currentRetry = 0, retryDelay = 1000) {
|
|
106
|
+
const nextRetryAt = Date.now() + retryDelay;
|
|
107
|
+
// Clone the error with updated context
|
|
108
|
+
const newContext = {
|
|
109
|
+
...this.context,
|
|
110
|
+
retry: {
|
|
111
|
+
maxRetries,
|
|
112
|
+
currentRetry,
|
|
113
|
+
nextRetryAt,
|
|
114
|
+
retryDelay
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
// Create a new instance using the protected method that subclasses can override
|
|
118
|
+
const newError = this.createWithContext(newContext);
|
|
119
|
+
// Update recoverability if we can retry
|
|
120
|
+
if (currentRetry < maxRetries && newError.recoverability === ErrorRecoverability.NON_RECOVERABLE) {
|
|
121
|
+
newError.recoverability = ErrorRecoverability.MAYBE_RECOVERABLE;
|
|
122
|
+
}
|
|
123
|
+
return newError;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Protected method to create a new instance with updated context
|
|
127
|
+
* Subclasses can override this to handle their own constructor signatures
|
|
128
|
+
*/
|
|
129
|
+
createWithContext(context) {
|
|
130
|
+
// Default implementation for PlatformError
|
|
131
|
+
return new this.constructor(this.message, this.code, this.severity, this.category, this.recoverability, context);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Checks if the error should be retried based on retry information
|
|
135
|
+
*/
|
|
136
|
+
shouldRetry() {
|
|
137
|
+
const { retry } = this.context;
|
|
138
|
+
if (!retry)
|
|
139
|
+
return false;
|
|
140
|
+
return (retry.currentRetry ?? 0) < (retry.maxRetries ?? 0);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Returns a user-friendly message that is safe to display to end users
|
|
144
|
+
*/
|
|
145
|
+
getUserMessage() {
|
|
146
|
+
return this.context.userMessage || 'An unexpected error occurred.';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Error class for validation errors
|
|
151
|
+
*/
|
|
152
|
+
export class ValidationError extends PlatformError {
|
|
153
|
+
/**
|
|
154
|
+
* Creates a new validation error
|
|
155
|
+
*
|
|
156
|
+
* @param message Error message
|
|
157
|
+
* @param code Error code
|
|
158
|
+
* @param context Additional context
|
|
159
|
+
*/
|
|
160
|
+
constructor(message, code, context = {}) {
|
|
161
|
+
super(message, code, ErrorSeverity.LOW, ErrorCategory.VALIDATION, ErrorRecoverability.NON_RECOVERABLE, context);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates a new instance with updated context
|
|
165
|
+
* Overrides the base implementation to handle ValidationError's constructor signature
|
|
166
|
+
*/
|
|
167
|
+
createWithContext(context) {
|
|
168
|
+
return new this.constructor(this.message, this.code, context);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Error class for configuration errors
|
|
173
|
+
*/
|
|
174
|
+
export class ConfigurationError extends PlatformError {
|
|
175
|
+
/**
|
|
176
|
+
* Creates a new configuration error
|
|
177
|
+
*
|
|
178
|
+
* @param message Error message
|
|
179
|
+
* @param code Error code
|
|
180
|
+
* @param context Additional context
|
|
181
|
+
*/
|
|
182
|
+
constructor(message, code, context = {}) {
|
|
183
|
+
super(message, code, ErrorSeverity.MEDIUM, ErrorCategory.CONFIGURATION, ErrorRecoverability.NON_RECOVERABLE, context);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Creates a new instance with updated context
|
|
187
|
+
* Overrides the base implementation to handle ConfigurationError's constructor signature
|
|
188
|
+
*/
|
|
189
|
+
createWithContext(context) {
|
|
190
|
+
return new this.constructor(this.message, this.code, context);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Error class for network-related errors
|
|
195
|
+
*/
|
|
196
|
+
export class NetworkError extends PlatformError {
|
|
197
|
+
/**
|
|
198
|
+
* Creates a new network error
|
|
199
|
+
*
|
|
200
|
+
* @param message Error message
|
|
201
|
+
* @param code Error code
|
|
202
|
+
* @param context Additional context
|
|
203
|
+
*/
|
|
204
|
+
constructor(message, code, context = {}) {
|
|
205
|
+
super(message, code, ErrorSeverity.MEDIUM, ErrorCategory.CONNECTIVITY, ErrorRecoverability.MAYBE_RECOVERABLE, context);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Creates a new instance with updated context
|
|
209
|
+
* Overrides the base implementation to handle NetworkError's constructor signature
|
|
210
|
+
*/
|
|
211
|
+
createWithContext(context) {
|
|
212
|
+
return new this.constructor(this.message, this.code, context);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Error class for resource availability errors (rate limits, quotas)
|
|
217
|
+
*/
|
|
218
|
+
export class ResourceError extends PlatformError {
|
|
219
|
+
/**
|
|
220
|
+
* Creates a new resource error
|
|
221
|
+
*
|
|
222
|
+
* @param message Error message
|
|
223
|
+
* @param code Error code
|
|
224
|
+
* @param context Additional context
|
|
225
|
+
*/
|
|
226
|
+
constructor(message, code, context = {}) {
|
|
227
|
+
super(message, code, ErrorSeverity.MEDIUM, ErrorCategory.RESOURCE, ErrorRecoverability.MAYBE_RECOVERABLE, context);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Creates a new instance with updated context
|
|
231
|
+
* Overrides the base implementation to handle ResourceError's constructor signature
|
|
232
|
+
*/
|
|
233
|
+
createWithContext(context) {
|
|
234
|
+
return new this.constructor(this.message, this.code, context);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Error class for authentication/authorization errors
|
|
239
|
+
*/
|
|
240
|
+
export class AuthenticationError extends PlatformError {
|
|
241
|
+
/**
|
|
242
|
+
* Creates a new authentication error
|
|
243
|
+
*
|
|
244
|
+
* @param message Error message
|
|
245
|
+
* @param code Error code
|
|
246
|
+
* @param context Additional context
|
|
247
|
+
*/
|
|
248
|
+
constructor(message, code, context = {}) {
|
|
249
|
+
super(message, code, ErrorSeverity.HIGH, ErrorCategory.AUTHENTICATION, ErrorRecoverability.NON_RECOVERABLE, context);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Creates a new instance with updated context
|
|
253
|
+
* Overrides the base implementation to handle AuthenticationError's constructor signature
|
|
254
|
+
*/
|
|
255
|
+
createWithContext(context) {
|
|
256
|
+
return new this.constructor(this.message, this.code, context);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Error class for operation errors (API calls, processing)
|
|
261
|
+
*/
|
|
262
|
+
export class OperationError extends PlatformError {
|
|
263
|
+
/**
|
|
264
|
+
* Creates a new operation error
|
|
265
|
+
*
|
|
266
|
+
* @param message Error message
|
|
267
|
+
* @param code Error code
|
|
268
|
+
* @param context Additional context
|
|
269
|
+
*/
|
|
270
|
+
constructor(message, code, context = {}) {
|
|
271
|
+
super(message, code, ErrorSeverity.MEDIUM, ErrorCategory.OPERATION, ErrorRecoverability.MAYBE_RECOVERABLE, context);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Creates a new instance with updated context
|
|
275
|
+
* Overrides the base implementation to handle OperationError's constructor signature
|
|
276
|
+
*/
|
|
277
|
+
createWithContext(context) {
|
|
278
|
+
return new this.constructor(this.message, this.code, context);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Error class for critical system errors
|
|
283
|
+
*/
|
|
284
|
+
export class SystemError extends PlatformError {
|
|
285
|
+
/**
|
|
286
|
+
* Creates a new system error
|
|
287
|
+
*
|
|
288
|
+
* @param message Error message
|
|
289
|
+
* @param code Error code
|
|
290
|
+
* @param context Additional context
|
|
291
|
+
*/
|
|
292
|
+
constructor(message, code, context = {}) {
|
|
293
|
+
super(message, code, ErrorSeverity.CRITICAL, ErrorCategory.OTHER, ErrorRecoverability.NON_RECOVERABLE, context);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Helper to get the appropriate error class based on error category
|
|
298
|
+
*
|
|
299
|
+
* @param category Error category
|
|
300
|
+
* @returns The appropriate error class
|
|
301
|
+
*/
|
|
302
|
+
export function getErrorClassForCategory(category) {
|
|
303
|
+
switch (category) {
|
|
304
|
+
case ErrorCategory.VALIDATION:
|
|
305
|
+
return ValidationError;
|
|
306
|
+
case ErrorCategory.CONFIGURATION:
|
|
307
|
+
return ConfigurationError;
|
|
308
|
+
case ErrorCategory.CONNECTIVITY:
|
|
309
|
+
return NetworkError;
|
|
310
|
+
case ErrorCategory.RESOURCE:
|
|
311
|
+
return ResourceError;
|
|
312
|
+
case ErrorCategory.AUTHENTICATION:
|
|
313
|
+
return AuthenticationError;
|
|
314
|
+
case ErrorCategory.OPERATION:
|
|
315
|
+
return OperationError;
|
|
316
|
+
default:
|
|
317
|
+
return PlatformError;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZS5lcnJvcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi90cy9lcnJvcnMvYmFzZS5lcnJvcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGFBQWEsRUFBRSxhQUFhLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNyRixPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0sY0FBYyxDQUFDO0FBb0R0Qzs7O0dBR0c7QUFDSCxNQUFNLE9BQU8sYUFBYyxTQUFRLEtBQUs7SUFDdEMscURBQXFEO0lBQ3JDLElBQUksQ0FBUztJQUU3QiwyQkFBMkI7SUFDWCxRQUFRLENBQWdCO0lBRXhDLGlEQUFpRDtJQUNqQyxRQUFRLENBQWdCO0lBRXhDLDREQUE0RDtJQUM1QyxjQUFjLENBQXNCO0lBRXBELHFDQUFxQztJQUNyQixPQUFPLENBQWdCO0lBRXZDOzs7Ozs7Ozs7T0FTRztJQUNILFlBQ0UsT0FBZSxFQUNmLElBQVksRUFDWixXQUEwQixhQUFhLENBQUMsTUFBTSxFQUM5QyxXQUEwQixhQUFhLENBQUMsS0FBSyxFQUM3QyxpQkFBc0MsbUJBQW1CLENBQUMsZUFBZSxFQUN6RSxVQUF5QixFQUFFO1FBRTNCLEtBQUssQ0FB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BQ3pCLENBQUM7QUFDSCxDQUFDIn0=
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { PlatformError } from './base.errors.js';
|
|
2
|
+
import type { IErrorContext } from './base.errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Error handler configuration
|
|
5
|
+
*/
|
|
6
|
+
export interface IErrorHandlerConfig {
|
|
7
|
+
/** Whether to log errors automatically */
|
|
8
|
+
logErrors: boolean;
|
|
9
|
+
/** Whether to include stack traces in prod environment */
|
|
10
|
+
includeStacksInProd: boolean;
|
|
11
|
+
/** Default retry options */
|
|
12
|
+
retry: {
|
|
13
|
+
/** Maximum retry attempts */
|
|
14
|
+
maxAttempts: number;
|
|
15
|
+
/** Base delay between retries in ms */
|
|
16
|
+
baseDelay: number;
|
|
17
|
+
/** Maximum delay between retries in ms */
|
|
18
|
+
maxDelay: number;
|
|
19
|
+
/** Backoff factor for exponential backoff */
|
|
20
|
+
backoffFactor: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Error handler utility
|
|
25
|
+
* Provides methods for consistent error handling across the platform
|
|
26
|
+
*/
|
|
27
|
+
export declare class ErrorHandler {
|
|
28
|
+
/**
|
|
29
|
+
* Current configuration
|
|
30
|
+
*/
|
|
31
|
+
static config: IErrorHandlerConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Update error handler configuration
|
|
34
|
+
*
|
|
35
|
+
* @param newConfig New configuration (partial)
|
|
36
|
+
*/
|
|
37
|
+
static configure(newConfig: Partial<IErrorHandlerConfig>): void;
|
|
38
|
+
/**
|
|
39
|
+
* Convert any error to a PlatformError
|
|
40
|
+
*
|
|
41
|
+
* @param error Error to convert
|
|
42
|
+
* @param defaultCode Default error code if not a PlatformError
|
|
43
|
+
* @param context Additional context
|
|
44
|
+
* @returns PlatformError instance
|
|
45
|
+
*/
|
|
46
|
+
static toPlatformError(error: any, defaultCode: string, context?: IErrorContext): PlatformError;
|
|
47
|
+
/**
|
|
48
|
+
* Format an error for API responses
|
|
49
|
+
* Sanitizes errors for safe external exposure
|
|
50
|
+
*
|
|
51
|
+
* @param error Error to format
|
|
52
|
+
* @param includeDetails Whether to include detailed information
|
|
53
|
+
* @returns Formatted error object
|
|
54
|
+
*/
|
|
55
|
+
static formatErrorForResponse(error: any, includeDetails?: boolean): Record<string, any>;
|
|
56
|
+
/**
|
|
57
|
+
* Handle an error with consistent logging and formatting
|
|
58
|
+
*
|
|
59
|
+
* @param error Error to handle
|
|
60
|
+
* @param defaultCode Default error code if not a PlatformError
|
|
61
|
+
* @param context Additional context
|
|
62
|
+
* @returns Formatted error for response
|
|
63
|
+
*/
|
|
64
|
+
static handleError(error: any, defaultCode: string, context?: IErrorContext): Record<string, any>;
|
|
65
|
+
/**
|
|
66
|
+
* Execute a function with error handling
|
|
67
|
+
*
|
|
68
|
+
* @param fn Function to execute
|
|
69
|
+
* @param defaultCode Default error code if the function throws
|
|
70
|
+
* @param context Additional context
|
|
71
|
+
* @returns Function result or error
|
|
72
|
+
*/
|
|
73
|
+
static execute<T>(fn: () => Promise<T>, defaultCode: string, context?: IErrorContext): Promise<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Execute a function with retries and exponential backoff
|
|
76
|
+
*
|
|
77
|
+
* @param fn Function to execute
|
|
78
|
+
* @param defaultCode Default error code if the function throws
|
|
79
|
+
* @param options Retry options
|
|
80
|
+
* @param context Additional context
|
|
81
|
+
* @returns Function result or error after max retries
|
|
82
|
+
*/
|
|
83
|
+
static executeWithRetry<T>(fn: () => Promise<T>, defaultCode: string, options?: {
|
|
84
|
+
maxAttempts?: number;
|
|
85
|
+
baseDelay?: number;
|
|
86
|
+
maxDelay?: number;
|
|
87
|
+
backoffFactor?: number;
|
|
88
|
+
retryableErrorCodes?: string[];
|
|
89
|
+
retryableErrorPatterns?: RegExp[];
|
|
90
|
+
onRetry?: (error: PlatformError, attempt: number, delay: number) => void;
|
|
91
|
+
}, context?: IErrorContext): Promise<T>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a middleware for handling errors in HTTP requests
|
|
95
|
+
*
|
|
96
|
+
* @returns Middleware function
|
|
97
|
+
*/
|
|
98
|
+
export declare function createErrorHandlerMiddleware(): (error: any, req: any, res: any, next: any) => void;
|