-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.js
43 lines (36 loc) · 1.08 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use strict";
function tryParseJSON(jsonString) {
try {
if (jsonString && typeof jsonString === "object") return jsonString;
let o = JSON.parse(jsonString);
if (o && typeof o === "object") {
return o;
}
}
catch (e) {
}
return false;
}
function validateASRConfig(asrConfig, serviceType) {
if (serviceType === "SQS") {
return asrConfig && asrConfig.triggerTopicName && asrConfig.failureTopicName && asrConfig.maxRetryAttempts ? true : false;
} else if (serviceType === "SNS") {
return asrConfig && asrConfig.retryTopicName && asrConfig.failureTopicName && asrConfig.successTopicName && asrConfig.maxRetryAttempts ? true : false;
}
return false;
}
function log(level, message, data) {
if (process.env.DEBUG) {
let logMessage = {
level: level,
message: message,
data: data
};
console.log(JSON.stringify(logMessage, null, 2));
}
}
module.exports = {
log: log,
validateASRConfig: validateASRConfig,
tryParseJSON: tryParseJSON
};