Skip to content

Commit 8e05417

Browse files
committed
major bump revert
1 parent 8682751 commit 8e05417

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

lib/modem.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Modem.prototype.dial = function (options, callback) {
164164
address = address.substring(0, address.length - 1);
165165
}
166166
}
167-
167+
168168
var optionsf = {
169169
path: address,
170170
method: options.method,
@@ -340,7 +340,7 @@ Modem.prototype.buildRequest = function (options, context, data, callback) {
340340

341341
debug('Received: %s', result);
342342

343-
var json = utils.parseJSON(result) || stream.Readable.from(buffer);
343+
var json = utils.parseJSON(result) || result;
344344
if (finished === false) {
345345
finished = true;
346346
self.buildPayload(null, context.isStream, context.statusCodes, false, req, res, json, callback);
@@ -376,6 +376,9 @@ Modem.prototype.buildPayload = function (err, isStream, statusCodes, openStdin,
376376

377377
if (statusCodes[res.statusCode] !== true) {
378378
getCause(isStream, res, json, function (err, cause) {
379+
if (err) {
380+
return cb(err, null);
381+
}
379382
var msg = new Error(
380383
'(HTTP code ' + res.statusCode + ') ' +
381384
(statusCodes[res.statusCode] || 'unexpected') + ' - ' +
@@ -398,16 +401,32 @@ Modem.prototype.buildPayload = function (err, isStream, statusCodes, openStdin,
398401

399402
function getCause(isStream, res, json, callback) {
400403
var chunks = '';
404+
var done = false;
405+
401406
if (isStream) {
402407
res.on('data', function (chunk) {
403408
chunks += chunk;
404409
});
410+
res.on('error', function (err) {
411+
handler(err, null);
412+
});
405413
res.on('end', function () {
406-
callback(null, utils.parseJSON(chunks) || chunks);
414+
handler(null, utils.parseJSON(chunks) || chunks)
407415
});
408416
} else {
409417
callback(null, json);
410418
}
419+
420+
function handler(err, data) {
421+
if (done === false) {
422+
if (err) {
423+
callback(err);
424+
} else {
425+
callback(null, data);
426+
}
427+
}
428+
done = true;
429+
}
411430
}
412431
};
413432

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "docker-modem",
33
"description": "Docker remote API network layer module.",
4-
"version": "4.0.1",
4+
"version": "5.0.0",
55
"author": "Pedro Dias <[email protected]>",
66
"maintainers": [
77
"apocas <[email protected]>"

0 commit comments

Comments
 (0)