-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix(fetch): fixup generators and add error handling #8395
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { OPENCOLLECTIVE_MEMBERS_URL } from '#site/next.constants.mjs'; | ||
| import { fetchWithRetry } from '#site/util/fetch'; | ||
|
|
||
| /** | ||
| * Fetches supporters data from Open Collective API, filters active backers, | ||
|
|
@@ -7,7 +8,7 @@ import { OPENCOLLECTIVE_MEMBERS_URL } from '#site/next.constants.mjs'; | |
| * @returns {Promise<Array<import('#site/types/supporters').OpenCollectiveSupporter>>} Array of supporters | ||
| */ | ||
| export default () => | ||
| fetch(OPENCOLLECTIVE_MEMBERS_URL) | ||
| fetchWithRetry(OPENCOLLECTIVE_MEMBERS_URL) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we please please revert the change from async functions to Promises. THANK YOU |
||
| .then(response => response.json()) | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .then(payload => | ||
| payload | ||
|
|
@@ -20,5 +21,4 @@ export default () => | |
| profile, | ||
| source: 'opencollective', | ||
| })) | ||
| ) | ||
| .catch(() => []); | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| export type Supporter = { | ||
| export type Supporter<T extends string> = { | ||
| name: string; | ||
| image: string; | ||
| url: string; | ||
| profile: string; | ||
| source: string; | ||
| source: T; | ||
| }; | ||
|
|
||
| export type OpenCollectiveSupporter = Supporter & { source: 'opencollective' }; | ||
| export type OpenCollectiveSupporter = Supporter<'opencollective'>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { setTimeout } from 'node:timers/promises'; | ||
|
|
||
| type RetryOptions = RequestInit & { | ||
| maxRetry: number; | ||
| delay: number; | ||
| }; | ||
|
|
||
| export const fetchWithRetry = async ( | ||
| url: string, | ||
| { maxRetry = 3, delay = 100, ...options }: RetryOptions | ||
| ) => { | ||
| for (let i = 1; i <= maxRetry; i++) { | ||
| try { | ||
| return fetch(url, options); | ||
| } catch (e) { | ||
| if (i === maxRetry) { | ||
| throw e; | ||
| } | ||
|
|
||
| await setTimeout(delay); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add a backoff
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYM?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A retry with backoff pattern |
||
| continue; | ||
| } | ||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.