octokit / request.js

Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node
MIT License
227 stars 61 forks source link

response.headers is not iterable error #445

Open yaronya opened 2 years ago

yaronya commented 2 years ago

Hi,

I'm using @octokit/rest as my GH rest client and I found a possible bug in https://github.com/octokit/request.js/blob/92e7e1c6609b694ba3cf69fa7a86efd9dbc6e5f3/src/fetch-wrapper.ts#L50 where I use a fetch wrapper that return headers as a non-iterable object. In that case, @octokit/request throws an error saying response.headers is not iterable.

I'd expect the package to iterate the headers attribute only if it exists and is iterable...

wolfy1339 commented 6 months ago

We switched to using the fetch API, which means that response.headers is a Headers instance, which is iterable. That whole for loop can be simplified to use a simple Object.fromEntries()

Can you describe what the response.headers looks like for you? Is it a simple object?

wolfy1339 commented 2 months ago

@yaronya Is this still an issue?

Uzlopak commented 1 month ago

I hit this issue also in #711

A plain object is not iterable. We could rewrite it, to accept plain objects, but on the other hand we want definetly set the condition to use a fetch implementation according to the spec.