-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreport-bug.js
62 lines (46 loc) · 1.54 KB
/
report-bug.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const http = require('http');
const https = require('https');
const { getConfigValue } = require('homegames-common');
const ERROR_REPORTING_ENABLED = getConfigValue('ERROR_REPORTING', false);
const HTTPS_ENABLED = true;//'https://api.homegames.io/bugs';//getConfigValue('HTTPS_ENABLED', false);
if (ERROR_REPORTING_ENABLED) {
reportingEndpoint = getConfigValue('ERROR_REPORTING_ENDPOINT', 'https://api.homegames.io/bugs');
}
const makePost = (exc) => new Promise((resolve, reject) => {
const payload = exc;//JSON.stringify(exc);
let module, hostname, port;
module = reportingEndpoint.startsWith('https') ? https : http;
port = reportingEndpoint.startsWith('https') ? 443 : 80;
hostname = new URL(reportingEndpoint).hostname;
const headers = {};
Object.assign(headers, {
'Content-Type': 'application/json',
'Content-Length': exc.length
});
const options = {
hostname,
path: new URL(reportingEndpoint).pathname,
port,
method: 'POST',
headers
};
let responseData = '';
const req = module.request(options, (res) => {
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
resolve(responseData);
});
});
req.write(exc);
req.end();
});
const reportBug = (err) => {
if (ERROR_REPORTING_ENABLED && reportingEndpoint) {
makePost(err.toString());
} else {
console.error('Reporting not enabled for bug: ' + err);
}
};
module.exports = reportBug;