Skip to content

Commit

Permalink
major bump revert
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Oct 11, 2023
1 parent 8682751 commit 8e05417
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
25 changes: 22 additions & 3 deletions lib/modem.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Modem.prototype.dial = function (options, callback) {
address = address.substring(0, address.length - 1);
}
}

var optionsf = {
path: address,
method: options.method,
Expand Down Expand Up @@ -340,7 +340,7 @@ Modem.prototype.buildRequest = function (options, context, data, callback) {

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

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

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

function getCause(isStream, res, json, callback) {
var chunks = '';
var done = false;

if (isStream) {
res.on('data', function (chunk) {
chunks += chunk;
});
res.on('error', function (err) {
handler(err, null);
});
res.on('end', function () {
callback(null, utils.parseJSON(chunks) || chunks);
handler(null, utils.parseJSON(chunks) || chunks)
});
} else {
callback(null, json);
}

function handler(err, data) {
if (done === false) {
if (err) {
callback(err);
} else {
callback(null, data);
}
}
done = true;
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "docker-modem",
"description": "Docker remote API network layer module.",
"version": "4.0.1",
"version": "5.0.0",
"author": "Pedro Dias <[email protected]>",
"maintainers": [
"apocas <[email protected]>"
Expand Down

0 comments on commit 8e05417

Please sign in to comment.