Skip to content
Open
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,29 @@ class Request {
res.on('end', () => {
logger('Request complete');


if (res.statusCode >= 400 && res.statusCode <= 600) {
if (shouldUnzip) {
const unzip = contentEncoding === 'deflate' ? zlib.deflate : zlib.gunzip;
return unzip(Buffer.from(body, encoding), (err, data) => {
if (err) {
return reject(err);
}

const error = new Error(`Request returned error code: ${res.statusCode} and body: ${data.toString('utf8')}`);
error.code = res.statusCode;
error.responseBody = data.toString('utf8');
return reject(error);
});
}

const error = new Error(`Request returned error code: ${res.statusCode} and body: ${body}`);
error.code = res.statusCode;
error.responseBody = body;

return reject(error);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these spaces

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syJSdev (removed)

// Use GZIP decompression if required
if (shouldUnzip) {
const unzip = contentEncoding === 'deflate' ? zlib.deflate : zlib.gunzip;
Expand Down