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

fix(browser): return early if response headers empty #1034

Merged
merged 1 commit into from
Aug 7, 2020

Conversation

kiprasmel
Copy link
Contributor

@kiprasmel kiprasmel commented Aug 2, 2020

When performing simple requests, such as

import { Gitlab } from "@gitbeaker/browser";

const api = new Gitlab({ token, host });

const res = await api.Issues.show(projectId, issueIid);

I used to get errors, such as

index.js:11539 RangeError: Invalid array length
    at ./gitbeaker/packages/gitbeaker-browser/src/KyRequester.ts.__spreadArrays (index.js:155)
    at responseHeadersAsObject (index.js:169)
    at index.js:224
    at step (index.js:148)
    at Object.next (index.js:129)
    at fulfilled (index.js:120)
(anonymous) @ index.js:11539
step @ index.js:11488
(anonymous) @ index.js:11469
rejected @ index.js:11461
Promise.then (async)
step @ index.js:11462
(anonymous) @ index.js:11463
./source/features/add-grid-for-current-column-label.tsx.__awaiter @ index.js:11459
addGridForCurrentColumnLabel @ index.js:11520
(anonymous) @ index.js:11375
step @ index.js:11345
(anonymous) @ index.js:11326
fulfilled @ index.js:11317
Promise.then (async)
step @ index.js:11319
(anonymous) @ index.js:11320
./source/Features.ts.__awaiter @ index.js:11316
(anonymous) @ index.js:11369
(anonymous) @ index.js:11380
./source/Features.ts.Features.loadAll @ index.js:11363
globalInit @ index.js:11810
./source/refined-gitlab.ts @ index.js:11667
__webpack_require__ @ index.js:20
./source/index.ts @ index.js:11637
__webpack_require__ @ index.js:20
(anonymous) @ index.js:84
(anonymous) @ index.js:87

and this fixed it.


__spreadArrays refers to the const keyVals = [...response.headers.entries()] line's array spread when the headers are empty ({})

(I'm using gitbeaker's direct source code as a git submodule instead of via npm because I tried both rollup & webpack and couldn't compile gitbeaker to work inside a browser extension. It's generally better to not compile libraries and leave it up to the final application, but whatever, I don't mind, and was able to fix this quicker - cheers)

When performing simple requests, such as

```ts
import { Gitlab } from "@gitbeaker/browser";

const api = new Gitlab({ token, host });

const res = await api.Issues.show(projectId, issueIid);
```

I used to get errors, such as

```console
index.js:11539 RangeError: Invalid array length
    at ./gitbeaker/packages/gitbeaker-browser/src/KyRequester.ts.__spreadArrays (index.js:155)
    at responseHeadersAsObject (index.js:169)
    at index.js:224
    at step (index.js:148)
    at Object.next (index.js:129)
    at fulfilled (index.js:120)
(anonymous) @ index.js:11539
step @ index.js:11488
(anonymous) @ index.js:11469
rejected @ index.js:11461
Promise.then (async)
step @ index.js:11462
(anonymous) @ index.js:11463
./source/features/add-grid-for-current-column-label.tsx.__awaiter @ index.js:11459
addGridForCurrentColumnLabel @ index.js:11520
(anonymous) @ index.js:11375
step @ index.js:11345
(anonymous) @ index.js:11326
fulfilled @ index.js:11317
Promise.then (async)
step @ index.js:11319
(anonymous) @ index.js:11320
./source/Features.ts.__awaiter @ index.js:11316
(anonymous) @ index.js:11369
(anonymous) @ index.js:11380
./source/Features.ts.Features.loadAll @ index.js:11363
globalInit @ index.js:11810
./source/refined-gitlab.ts @ index.js:11667
__webpack_require__ @ index.js:20
./source/index.ts @ index.js:11637
__webpack_require__ @ index.js:20
(anonymous) @ index.js:84
(anonymous) @ index.js:87
```

and this fixed it.
@jdalrymple jdalrymple merged commit 2b65591 into jdalrymple:master Aug 7, 2020
@jdalrymple jdalrymple added the bug label Aug 9, 2020
@jdalrymple
Copy link
Owner

Forgot to add the correct tag before merging! This will be included in the next triggered release 🙏 sorry!!

@jdalrymple
Copy link
Owner

🚀 PR was released in 23.5.0 🚀

kiprasmel pushed a commit to kiprasmel/refined-gitlab that referenced this pull request Aug 9, 2020
kiprasmel pushed a commit to kiprasmel/refined-gitlab that referenced this pull request Aug 9, 2020
@kiprasmel
Copy link
Contributor Author

cheers m8, thanks for the great project! hopefully will be able to implement some cool stuff with it @ refined-gitlab :D

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

Successfully merging this pull request may close these issues.

2 participants