Fix flaky tests (#3724)

* adds continuation to silence rejected promises

* Wrap json parsing
This commit is contained in:
Florent Vilmart
2017-04-16 16:50:03 -04:00
committed by GitHub
parent dcd8e5626a
commit 5813fd0bf8
12 changed files with 63 additions and 14 deletions

View File

@@ -41,7 +41,7 @@ function request(api_key, auth_token) {
}
};
return new Promise(function (resolve) {
return new Promise(function (resolve, reject) {
// Create the post request.
var post_req = https.request(post_options, function (res) {
var data = '';
@@ -52,7 +52,12 @@ function request(api_key, auth_token) {
});
// Once we have all the data, we can parse it and return the data we want.
res.on('end', function () {
resolve(JSON.parse(data));
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
});