playov2-js-utilities 0.3.44 → 0.3.46
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/lib/index.js
CHANGED
|
@@ -12,5 +12,6 @@ module.exports = {
|
|
|
12
12
|
Cron: require('./cron'),
|
|
13
13
|
MessagePublisher: require('./message_publisher'),
|
|
14
14
|
middleware: require('./middleware'),
|
|
15
|
-
profanityFilter: require("./profanityFilter/profanityFilter")
|
|
15
|
+
profanityFilter: require("./profanityFilter/profanityFilter"),
|
|
16
|
+
playoResponseHandler: require("./responseHandler/responseHandler")
|
|
16
17
|
};
|
|
@@ -3,7 +3,7 @@ const Filter = require("bad-words");
|
|
|
3
3
|
const profanityFilter = new Filter();
|
|
4
4
|
const profanityWordList = profanityWords.split(",");
|
|
5
5
|
|
|
6
|
-
profanityFilter.addWords(profanityWordList);
|
|
6
|
+
profanityFilter.addWords(...profanityWordList);
|
|
7
7
|
|
|
8
8
|
const checkProfanity = (message) => {
|
|
9
9
|
return profanityFilter.isProfane(message);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const Logger = require("../logger");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Axios response handler
|
|
5
|
+
* @param {Response} resp
|
|
6
|
+
* resp structure |
|
|
7
|
+
* on success {
|
|
8
|
+
* status: HTTP status code returned by the service
|
|
9
|
+
* data,
|
|
10
|
+
* config: request config
|
|
11
|
+
* }
|
|
12
|
+
* on fail : {
|
|
13
|
+
* code: error code | http errorcode like ECONNREFUSED, ETIMEOUT etc
|
|
14
|
+
* message: error message | description of the error code
|
|
15
|
+
* config: request config
|
|
16
|
+
* }
|
|
17
|
+
* @param {String} requestId
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
const responseHandler = (resp, requestId) => {
|
|
21
|
+
if (resp.isAxiosError) {
|
|
22
|
+
//if axios error is triggered then axios throws HTTP code for timeout or other forms of unsuccessful errors
|
|
23
|
+
const {
|
|
24
|
+
code = "UNCAUGHT_ERROR",
|
|
25
|
+
message = "encountered uncaught error",
|
|
26
|
+
config = { url: '' },
|
|
27
|
+
response = { data: { requestStatus: 0 } }
|
|
28
|
+
} = resp;
|
|
29
|
+
const { url } = config;
|
|
30
|
+
const { data } = response;
|
|
31
|
+
data["message"] = message;
|
|
32
|
+
Logger.prepareErrorLog(requestId, { code, message }, `Api call to url to ${url} failed`)
|
|
33
|
+
throw (data);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { status, data, config = { url: '' } } = resp;
|
|
37
|
+
const { url = '' } = config;
|
|
38
|
+
if (status === 200) {
|
|
39
|
+
const { requestStatus } = data;
|
|
40
|
+
if (!requestStatus && requestStatus != 0) { //if the service does not provide request status
|
|
41
|
+
data["requestStatus"] = 1;
|
|
42
|
+
}
|
|
43
|
+
Logger.prepareInfoLog(requestId, data, `Api call to url to ${url} succeeded with status ${status}`)
|
|
44
|
+
return data
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
else { // ideally this should not get triggered unless there is fault in calling lib itself
|
|
48
|
+
Logger.prepareErrorLog(requestId, err.stack, "axios error");
|
|
49
|
+
throw ({ requestStatus: 0, message: "Failed to handle response" })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { responseHandler }
|