mikeal / bent

Functional JS HTTP client (Node.js & Fetch) w/ async await

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

responseBody in the StatusError object does not get unzipped when the server uses gzip encoding

nicholas-ochoa opened this issue · comments

I noticed when handling StatusError thrown when the server returns an HTTP 400 error, the responseBody promise resolves to a Buffer containing the raw gzipped data returned by the server.

const get = bent('http://www.api.com', 'GET', 'json');
const url = '/endpoint';

try {
  response = await get(url);
} catch (err) {
  err.responseBody.then(body => {
    console.log(body);
  });
}

I would expect the err.responseBody promise to resolve to a buffer (or optionally string?) containing the decompressed data.