@steedos-labs/plugin-workflow 3.0.99 → 3.0.101
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.
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const { getWebhookErrorMessage } = require('../../../src/webhook_error');
|
|
3
|
+
|
|
4
|
+
console.log('[webhook-error-message] running tests...');
|
|
5
|
+
|
|
6
|
+
assert.strictEqual(
|
|
7
|
+
getWebhookErrorMessage({
|
|
8
|
+
message: 'Request failed with status code 500',
|
|
9
|
+
response: { data: 'name is required' }
|
|
10
|
+
}),
|
|
11
|
+
'name is required'
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
assert.strictEqual(
|
|
15
|
+
getWebhookErrorMessage({ response: { data: { errcode: 400, message: '参数错误' } } }),
|
|
16
|
+
'{"errcode":400,"message":"参数错误"}'
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
assert.strictEqual(
|
|
20
|
+
getWebhookErrorMessage(new Error('connect ECONNREFUSED')),
|
|
21
|
+
'connect ECONNREFUSED'
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const circularResponse = {};
|
|
25
|
+
circularResponse.self = circularResponse;
|
|
26
|
+
assert.strictEqual(
|
|
27
|
+
getWebhookErrorMessage({
|
|
28
|
+
message: 'Request failed with circular response data',
|
|
29
|
+
response: { data: circularResponse }
|
|
30
|
+
}),
|
|
31
|
+
'Request failed with circular response data'
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
assert.strictEqual(getWebhookErrorMessage('network error'), 'network error');
|
|
35
|
+
assert.strictEqual(getWebhookErrorMessage(null), 'Unknown webhook error');
|
|
36
|
+
|
|
37
|
+
console.log('[webhook-error-message] all tests passed');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos-labs/plugin-workflow",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.101",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"test:approve-values": "node main/default/test/test_getApproveValues.js",
|
|
28
28
|
"test:skip-handler-error": "node main/default/test/test_handleSkipProcessed_handlerError.js",
|
|
29
29
|
"test:flow-validator": "node main/default/test/test_flow_validator.js",
|
|
30
|
-
"test:ajax-error-message": "node main/default/test/test_ajax_error_message.js"
|
|
30
|
+
"test:ajax-error-message": "node main/default/test/test_ajax_error_message.js",
|
|
31
|
+
"test:webhook-error-message": "node main/default/test/test_webhook_error_message.js"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"graphql-parse-resolve-info": "^4.12.3",
|
package/package.service.js
CHANGED
|
@@ -7,6 +7,7 @@ const rests = require('./src/rests');
|
|
|
7
7
|
const InstanceRecordQueue = require('./src/instance_record_queue')
|
|
8
8
|
const WebhookQueue = require('./src/webhook_queue')
|
|
9
9
|
const TimeoutAutoSubmit = require('./src/timeout_auto_submit')
|
|
10
|
+
const { getCollection } = require('./main/default/utils/collection')
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @typedef {import('moleculer').Context} Context Moleculer's Context
|
|
@@ -140,6 +141,8 @@ module.exports = {
|
|
|
140
141
|
* Service started lifecycle event handler
|
|
141
142
|
*/
|
|
142
143
|
async started(ctx) {
|
|
144
|
+
WebhookQueue.collection = await getCollection('_webhook_queue');
|
|
145
|
+
|
|
143
146
|
// 注册 app_launcher widgets: 待审核、已审核
|
|
144
147
|
try {
|
|
145
148
|
const widgetsObj = this.getObject('widgets');
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Convert Axios and generic errors to a MongoDB-safe string while preserving
|
|
3
|
+
* the downstream response body whenever one is available.
|
|
4
|
+
*/
|
|
5
|
+
const getWebhookErrorMessage = function (error) {
|
|
6
|
+
const responseData = error && error.response && error.response.data;
|
|
7
|
+
|
|
8
|
+
if (responseData !== undefined && responseData !== null && responseData !== '') {
|
|
9
|
+
if (typeof responseData === 'string') {
|
|
10
|
+
return responseData;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const serializedResponse = JSON.stringify(responseData);
|
|
15
|
+
if (typeof serializedResponse === 'string') {
|
|
16
|
+
return serializedResponse;
|
|
17
|
+
}
|
|
18
|
+
} catch (stringifyError) {
|
|
19
|
+
// Fall through to the regular error message for circular response data.
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (error && error.message) {
|
|
24
|
+
return String(error.message);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (responseData !== undefined && responseData !== null) {
|
|
28
|
+
return String(responseData);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return error ? String(error) : 'Unknown webhook error';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
getWebhookErrorMessage
|
|
36
|
+
};
|
package/src/webhook_queue.js
CHANGED
|
@@ -10,6 +10,7 @@ const _ = require("lodash");
|
|
|
10
10
|
const axios = require('axios');
|
|
11
11
|
|
|
12
12
|
const { getCollection } = require("../main/default/utils/collection");
|
|
13
|
+
const { getWebhookErrorMessage } = require('./webhook_error');
|
|
13
14
|
|
|
14
15
|
const WebhookQueue = {};
|
|
15
16
|
|
|
@@ -123,13 +124,14 @@ WebhookQueue.Configure = async function (options) {
|
|
|
123
124
|
|
|
124
125
|
}
|
|
125
126
|
} catch (error) {
|
|
126
|
-
|
|
127
|
+
const errMsg = getWebhookErrorMessage(error);
|
|
128
|
+
console.error('WebhookQueue: Error while sending:', errMsg);
|
|
127
129
|
await WebhookQueue.collection.updateOne({
|
|
128
130
|
_id: webhook._id
|
|
129
131
|
}, {
|
|
130
132
|
$set: {
|
|
131
133
|
// error message
|
|
132
|
-
errMsg:
|
|
134
|
+
errMsg: errMsg
|
|
133
135
|
}
|
|
134
136
|
});
|
|
135
137
|
}
|
|
@@ -280,4 +282,4 @@ WebhookQueue.Configure = async function (options) {
|
|
|
280
282
|
|
|
281
283
|
};
|
|
282
284
|
|
|
283
|
-
module.exports = WebhookQueue;
|
|
285
|
+
module.exports = WebhookQueue;
|