|
|
@@ -70,22 +70,28 @@ Slack.prototype.onRequest = function(knownVersion, cb) {
|
|
|
};
|
|
|
|
|
|
function httpsRequest(url, cb) {
|
|
|
- https.get(url, (res) => {
|
|
|
- if (res.statusCode !== 200) {
|
|
|
- cb(res.statusCode, null);
|
|
|
- return;
|
|
|
- }
|
|
|
- var body = null;
|
|
|
- res.on('data', (chunk) => {
|
|
|
- body = body ? Buffer.concat([body, chunk], body.length +chunk.length) : Buffer.from(chunk);
|
|
|
- });
|
|
|
- res.on('end', () => {
|
|
|
- try {
|
|
|
- body = JSON.parse(body.toString("utf8"));
|
|
|
- } catch (e) {}
|
|
|
- cb && cb(res.statusCode, body);
|
|
|
+ try {
|
|
|
+ https.get(url, (res) => {
|
|
|
+ if (res.statusCode !== 200) {
|
|
|
+ cb(res.statusCode, null);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var body = null;
|
|
|
+ res.on('data', (chunk) => {
|
|
|
+ body = body ? Buffer.concat([body, chunk], body.length +chunk.length) : Buffer.from(chunk);
|
|
|
+ });
|
|
|
+ res.on('end', () => {
|
|
|
+ try {
|
|
|
+ body = JSON.parse(body.toString("utf8"));
|
|
|
+ } catch (e) {}
|
|
|
+ cb && cb(res.statusCode, body);
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ console.error("Error in https request: ", e);
|
|
|
+ cb && cb(0, null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Slack.prototype.connect = function(knownVersion) {
|