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

Retry does not work when using request body #46

Open
perjo927 opened this issue Mar 11, 2023 · 5 comments
Open

Retry does not work when using request body #46

perjo927 opened this issue Mar 11, 2023 · 5 comments

Comments

@perjo927
Copy link

perjo927 commented Mar 11, 2023

Hi @estrattonbailey,

I have encountered a problem when using the retry option. It works fine as long as I don't use a request body.

I couldn't figure it out, I debugged and it failed silently in handleRetry. Then I cloned the repo and wrapped a code block in a try/catch:

/* handleRetry.ts */

export async function handleRetry(
	request: () => Promise<Response>,
	method: string,
	retryOptions: Partial<RetryOptions>
) {
	let res;
        // Added try/catch heree
	try {
		res = await request();
	} catch (e) {
		console.log(e);
		return;
	}

Now fetch throws the following error:

Failed to execute 'fetch' on 'Window': Cannot construct a Request with a Request object that has already been used

It appears to happen only when a body is attached to the request, without a request body it works fine.

This answer helped me solve the problem: https://stackoverflow.com/a/55980308/3504096

If I clone the request here: https://github.com/truework/gretchen/blob/master/index.ts#L108-L111

... it works, like so:

/* index.ts */
  const fetcher = () =>
    timeout
      ? handleTimeout(fetch(request.clone()), timeout, controller)
      : fetch(request.clone())

I wanted to submit a pull request but was not authorized to do so.

@perjo927
Copy link
Author

perjo927 commented Mar 11, 2023

Plus, the exponential backoff does not seem to work like described in the docs (6, 36, 216, ...), it generates 6, 36, 1296, 1679616 instead

@perjo927
Copy link
Author

Will try forking, for now

@estrattonbailey
Copy link
Collaborator

Hey @perjo927 sorry for the delay. Will try to have a look at this this week!

@perjo927
Copy link
Author

perjo927 commented Jul 6, 2023

@estrattonbailey Thanks!

@ssolders
Copy link

any update on this? @estrattonbailey

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

3 participants