Skip to content

Commit e230496

Browse files
robertlongmattt
andauthored
Fix fetch scoping for cloudflare workers (#145)
* Fix fetch scoping for cloudflare workers * Apply suggestions from code review * Fix linting error --------- Co-authored-by: Mattt Zmuda <[email protected]>
1 parent 8f4c8e6 commit e230496

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ class Replicate {
211211
const shouldRetry = method === 'GET' ?
212212
(response) => (response.status === 429 || response.status >= 500) :
213213
(response) => (response.status === 429);
214-
const response = await withAutomaticRetries(async () => this.fetch(url, init), { shouldRetry });
214+
215+
// Workaround to fix `TypeError: Illegal invocation` error in Cloudflare Workers
216+
// https://github.com/replicate/replicate-javascript/issues/134
217+
const _fetch = this.fetch; // eslint-disable-line no-underscore-dangle
218+
const response = await withAutomaticRetries(async () => _fetch(url, init), { shouldRetry });
215219

216220
if (!response.ok) {
217221
const request = new Request(url, init);

0 commit comments

Comments
 (0)