serviejs / popsicle

Simple HTTP requests for node and the browser
MIT License
246 stars 19 forks source link

Unexpected end of file at zlib._handle.onerror #115

Closed Feverqwe closed 4 years ago

Feverqwe commented 6 years ago

Hello! I use this code and url response gzip.

const request = popsicle.request({
  method: 'GET',
  url: url,
  transport: popsicle.createTransport({
    type: 'stream'
  })
});
return request.then(function (res) {
  res.body.on('error', err => {});

  if (res.status !== 200) {
    request.abort();
    throw new Error('Bad status');
  }

  ...
});

If status will not 200 and I don't add after then this code:

res.body.on('error', err => {});

Will throw zlib error as Uncaught exception without stack. It is ok?

blakeembrey commented 6 years ago

This is the expected behaviour, you need to handle any streaming issues when you abort because the response would end prematurely. I don't have a good idea on how to resolve this yet, but have thought about it in the past (what you did is exactly what I've been doing). One other idea would be to catch this error inside the module by injecting into error handler when you call abort. What do you think?

Feverqwe commented 6 years ago

I don't know, how to do better. But just need know about this exception. Maybe need write about it in documentation.

blakeembrey commented 4 years ago

I believe this has been improved with the new API design based on servie.