@onlineapps/error-handler-core 1.0.0 → 1.1.1
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/package.json +2 -2
- package/src/DLQRouter.js +46 -0
- package/src/ErrorHandlerCore.js +4 -2
- package/src/UnifiedLogSchema.js +2 -1
- package/src/config.js +25 -0
- package/src/defaults.js +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/error-handler-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Core error handling functionality for OA Drive microservices - classification, retry, circuit breaker, DLQ routing",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@onlineapps/monitoring-core": "^1.0.0",
|
|
24
|
+
"@onlineapps/runtime-config": "1.0.1",
|
|
24
25
|
"opossum": "^7.0.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
@@ -31,4 +32,3 @@
|
|
|
31
32
|
"access": "public"
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
|
package/src/DLQRouter.js
CHANGED
|
@@ -8,6 +8,7 @@ class DLQRouter {
|
|
|
8
8
|
this.enabled = config.dlqEnabled !== false;
|
|
9
9
|
this.mqClient = config.mqClient || null;
|
|
10
10
|
this.dlqNamePattern = config.dlqNamePattern || '{queue}.dlq';
|
|
11
|
+
this.emitMonitoringEvents = config.emitMonitoringEvents !== false;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -51,6 +52,11 @@ class DLQRouter {
|
|
|
51
52
|
await this.mqClient.publish(dlqName, dlqMessage, {
|
|
52
53
|
persistent: true
|
|
53
54
|
});
|
|
55
|
+
|
|
56
|
+
// Emit message_dlq monitoring event
|
|
57
|
+
if (this.emitMonitoringEvents) {
|
|
58
|
+
await this._emitDLQEvent(message, dlqName, originalQueue, error, errorType, context);
|
|
59
|
+
}
|
|
54
60
|
} catch (dlqError) {
|
|
55
61
|
// If DLQ routing fails, log but don't throw
|
|
56
62
|
// (we don't want DLQ failures to break error handling)
|
|
@@ -58,6 +64,46 @@ class DLQRouter {
|
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Emit message_dlq event to monitoring
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async _emitDLQEvent(message, dlqName, originalQueue, error, errorType, context) {
|
|
72
|
+
if (!this.mqClient) return;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const workflowId = message.workflow_id || context.workflow_id || 'unknown';
|
|
76
|
+
|
|
77
|
+
await this.mqClient.publish('monitoring.workflow', {
|
|
78
|
+
event_type: 'message_dlq',
|
|
79
|
+
workflow_id: workflowId,
|
|
80
|
+
service_name: 'dlq-router',
|
|
81
|
+
step_id: 'dlq-entry',
|
|
82
|
+
timestamp: new Date().toISOString(),
|
|
83
|
+
context: {
|
|
84
|
+
_dlq: {
|
|
85
|
+
queue: dlqName,
|
|
86
|
+
originalQueue: originalQueue,
|
|
87
|
+
reason: error.message,
|
|
88
|
+
errorType: errorType,
|
|
89
|
+
retryCount: message.retryCount || context.retryCount || 0,
|
|
90
|
+
routedAt: new Date().toISOString()
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
metadata: {
|
|
94
|
+
dlq_queue: dlqName,
|
|
95
|
+
original_queue: originalQueue,
|
|
96
|
+
error_type: errorType
|
|
97
|
+
}
|
|
98
|
+
}, { persistent: true });
|
|
99
|
+
|
|
100
|
+
console.log(`[DLQRouter] ✓ Emitted message_dlq event for ${workflowId}`);
|
|
101
|
+
} catch (emitError) {
|
|
102
|
+
// Silent fail - don't break DLQ routing
|
|
103
|
+
console.warn(`[DLQRouter] Failed to emit monitoring event:`, emitError.message);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
61
107
|
/**
|
|
62
108
|
* Generate DLQ name from original queue name
|
|
63
109
|
* @private
|
package/src/ErrorHandlerCore.js
CHANGED
|
@@ -9,6 +9,7 @@ const RetryHandler = require('./RetryHandler');
|
|
|
9
9
|
const CircuitBreakerManager = require('./CircuitBreaker');
|
|
10
10
|
const DLQRouter = require('./DLQRouter');
|
|
11
11
|
const CompensationHandler = require('./CompensationHandler');
|
|
12
|
+
const runtimeCfg = require('./config');
|
|
12
13
|
|
|
13
14
|
class ErrorHandlerCore {
|
|
14
15
|
/**
|
|
@@ -38,8 +39,9 @@ class ErrorHandlerCore {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
this.serviceName = config.serviceName;
|
|
41
|
-
|
|
42
|
-
this.
|
|
42
|
+
const resolved = runtimeCfg.resolve(config);
|
|
43
|
+
this.serviceVersion = config.serviceVersion || resolved.serviceVersion;
|
|
44
|
+
this.environment = config.environment || resolved.environment;
|
|
43
45
|
this.monitoring = config.monitoring;
|
|
44
46
|
|
|
45
47
|
const handling = config.handling || {};
|
package/src/UnifiedLogSchema.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const os = require('os');
|
|
7
|
+
const runtimeCfg = require('./config');
|
|
7
8
|
|
|
8
9
|
class UnifiedLogSchema {
|
|
9
10
|
/**
|
|
@@ -74,7 +75,7 @@ class UnifiedLogSchema {
|
|
|
74
75
|
// Metadata
|
|
75
76
|
metadata: {
|
|
76
77
|
severity: this._determineSeverity(errorType),
|
|
77
|
-
environment:
|
|
78
|
+
environment: runtimeCfg.get('environment', environment),
|
|
78
79
|
version: serviceVersion || '0.0.0',
|
|
79
80
|
hostname: os.hostname(),
|
|
80
81
|
pid: process.pid
|
package/src/config.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runtime configuration schema for @onlineapps/error-handler-core.
|
|
5
|
+
*
|
|
6
|
+
* Uses @onlineapps/runtime-config for unified priority:
|
|
7
|
+
* 1. Explicit config
|
|
8
|
+
* 2. Environment variable
|
|
9
|
+
* 3. Module-owned defaults (from ./defaults.js)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { createRuntimeConfig } = require('@onlineapps/runtime-config');
|
|
13
|
+
const DEFAULTS = require('./defaults');
|
|
14
|
+
|
|
15
|
+
const runtimeCfg = createRuntimeConfig({
|
|
16
|
+
defaults: DEFAULTS,
|
|
17
|
+
schema: {
|
|
18
|
+
environment: { env: 'NODE_ENV', defaultKey: 'environment' },
|
|
19
|
+
serviceVersion: { env: 'SERVICE_VERSION', defaultKey: 'serviceVersion' },
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
module.exports = runtimeCfg;
|
|
24
|
+
|
|
25
|
+
|
package/src/defaults.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Module-owned defaults for @onlineapps/error-handler-core.
|
|
5
|
+
*
|
|
6
|
+
* Ownership rule:
|
|
7
|
+
* - Defaults in this file belong to error-handler-core (metadata defaults).
|
|
8
|
+
* - Service identity should be provided explicitly by callers.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
environment: 'development',
|
|
13
|
+
serviceVersion: '0.0.0',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
|