Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ module.exports.sendHttp = async function (_data, _host, _port, _path, _auth) {
return new Promise((resolve, reject) => {
var req = http.request(options, (res) => {
if (res.statusCode < 200 || res.statusCode > 299) {
reject(new Error('Failed to process the request, status Code: ', res.statusCode));
// Without `return`, the request continued to drain
// `data`/`end` and called `resolve(result)` later, settling
// the promise twice (#11).
return reject(new Error('Failed to process the request, status Code: ', res.statusCode));
}
res.setEncoding('utf8');
var dataBuffer = '';
Expand All @@ -30,7 +33,10 @@ module.exports.sendHttp = async function (_data, _host, _port, _path, _auth) {
res.on('end', () => {
xml2jsparser(dataBuffer, (err, result) => {
if (err) {
reject(new Error('Data Parsing error', err));
// Same shape: the `resolve(result)` below ran
// immediately after `reject` and the promise
// settled twice (#11).
return reject(new Error('Data Parsing error', err));
}
resolve(result);
});
Expand Down