From d1da542a00241f5bc17cc48535e6644d7de81df5 Mon Sep 17 00:00:00 2001 From: Andrew Dalgleish Date: Mon, 10 Dec 2018 14:47:55 -0800 Subject: [PATCH 1/2] Fix TypeError when rawBody returns err When `raw-body` returns an `err`, the callback will be called with an undefined `string` parameter. This change logs some detail about the errpr provided by [raw-body](https://github.com/stream-utils/raw-body#errors) and rejects the promise. --- lib/pxproxy.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pxproxy.js b/lib/pxproxy.js index dd44776e..2d820059 100644 --- a/lib/pxproxy.js +++ b/lib/pxproxy.js @@ -228,6 +228,10 @@ function parseBody(req) { limit: '1mb', encoding: contentType.parse(req).parameters.charset }, function (err, string) { + if (err) { + pxLogger.debug(`Could not parse raw request body. limit: ${err.limit} encoding: ${err.encoding} status: ${err.status} error type: ${err.type}`); + return reject(err); + } req.rawBody = string.toString(); resolve(); }) From d9d8ee37dd2767e6d05247d4de936dc636ce1c07 Mon Sep 17 00:00:00 2001 From: Yaron Schwimmer Date: Tue, 11 Dec 2018 16:59:40 +0200 Subject: [PATCH 2/2] Update pxproxy.js --- lib/pxproxy.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pxproxy.js b/lib/pxproxy.js index 6517defb..cd306681 100644 --- a/lib/pxproxy.js +++ b/lib/pxproxy.js @@ -237,13 +237,13 @@ function parseBody(req) { limit: '1mb', encoding: contentType.parse(req).parameters.charset }, function (err, string) { - if (err) { - pxLogger.debug(`Could not parse raw request body. limit: ${err.limit} encoding: ${err.encoding} status: ${err.status} error type: ${err.type}`); - return reject(err); - } - req.rawBody = string.toString(); - resolve(); - }); + if (err) { + pxLogger.debug(`Could not parse raw request body. limit: ${err.limit} encoding: ${err.encoding} status: ${err.status} error type: ${err.type}`); + return resolve(); + } + req.rawBody = string.toString(); + resolve(); + }); } else { if (typeof(req.body) === 'object') { if (req.headers['content-type'] === 'application/json') {