Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled error in deflate compression handling #45

Closed
pocketjoso opened this issue Sep 18, 2015 · 8 comments
Closed

Unhandled error in deflate compression handling #45

pocketjoso opened this issue Sep 18, 2015 · 8 comments

Comments

@pocketjoso
Copy link

Okay, I have to admit that I have no idea what's going on here, sorry for the vague issue.

Node v0.12.7

var fetch = require('node-fetch')
fetch('http://time-attendance.co.uk')

gives

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: incorrect header check
    at Zlib._handle.onerror (zlib.js:366:17)

...
The fetch results in a ok response... The promise is not rejected. But I still get this error thrown, somewhere.. Confused. :/

@pocketjoso
Copy link
Author

Ah. Just curled that url. A redirect? Not supported in this library?

@pocketjoso pocketjoso changed the title incorrect header check error How to handle redirect error? Sep 18, 2015
@pocketjoso
Copy link
Author

How do I handle this error? And is it possible to follow the redirect using fetch-node?

@pocketjoso pocketjoso changed the title How to handle redirect error? How to handle redirects? Sep 18, 2015
@bitinn
Copy link
Collaborator

bitinn commented Sep 19, 2015

Yep, node-fetch follows redirect by default, so the problem is not the redirect itself, but somehow node.js zlib is not able to handle the deflate response this server is returning.

https://github.com/bitinn/node-fetch/blob/master/index.js#L141

As we do test for deflate response support, my guess would be that particular server is returning something weird.

https://github.com/bitinn/node-fetch/blob/master/test/server.js#L67-L74
https://github.com/bitinn/node-fetch/blob/master/test/test.js#L329-L338

As a workaround for now, setting options compress: false will cause the server to return decompressed content, allowing your fetch to go through.

Neverthless, I think in this case we need to handle this error so that fetch reject the result (to truly fix the problem require checking what went wrong during zlib inflate, maybe open a ticket on node.js core?)

@pocketjoso
Copy link
Author

Thanks for your reply.

I think in this case we need to handle this error so that fetch reject the result

Yeah I think so too. As it is now I seem to have no way to handle the error, and I would prefer receive an Error rather than changing the compression mode (I'm making many requests).

to truly fix the problem require checking what went wrong during zlib inflate, maybe open a ticket on node.js core?

Not very read up on these things. How would I be able to tell what wen't wrong during the inflate? Would I not need to get onto the server serving that url? Nvm, I see that the inflate happens on the receiving end. Will do some more research. Will also try doing the same fetch in a browser to see what happens there.

@pocketjoso pocketjoso changed the title How to handle redirects? Unhandled error Sep 19, 2015
@pocketjoso pocketjoso changed the title Unhandled error Unhandled error in deflate compression handling Sep 19, 2015
@bitinn
Copy link
Collaborator

bitinn commented Sep 19, 2015

@pocketjoso I plan to work on this module next week, will update when the fix has landed.

@pocketjoso
Copy link
Author

Awesome. :)

@bitinn
Copy link
Collaborator

bitinn commented Sep 28, 2015

Fixed in v1.3.3, just note that we can't reject the fetch request (because the error is on body, which is a stream) but we do reject it when you call res.text() or res.json().

Otherwise you can use res.body.on('error', handler) to catch it independently.

@bitinn bitinn closed this as completed Sep 28, 2015
@pocketjoso
Copy link
Author

Excellent, thanks for fixing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants