Skip to content

Latest version of 'retry' no longer includes error #638

Closed

Description

@onionhammer

Just tried out upgrading to 2.4.0, and I see now that I can no longer check the error before retrying?

This was my logic

const queryConfig: ReactQueryProviderConfig<any> = {
    refetchOnWindowFocus: false,
    suspense: true,
    retry: (failures, err) => {
        if ("status" in err && err.status === 401)
            return false;
        else
            return failures < 5;
    }
};

Not sure how I would reproduce this with the new API, since the onError expects void, retryDelay does not give an error, and retry no longer takes a function.

Activity

  1. tannerlinsley commented on Jun 26, 2020

    @tannerlinsley
    Member

    Is this a types restriction, or have you tried this without types?

  2. onionhammer commented on Jun 26, 2020

    @onionhammer
    Author

    @tannerlinsley If I add in a ts-expect-error it compiles, but no longer works, the 'retry' function is no longer invoked in the newest version of react-query

    const queryConfig: ReactQueryProviderConfig = {
        refetchOnWindowFocus: false,
        suspense: true,
        // @ts-expect-error
        retry: (failures, err) => {
            if ("status" in err && err.status === 401)
                return false;
            else
                return failures < 5;
        }
    };
  3. bugzpodder commented on Jun 27, 2020

    @bugzpodder
    Contributor

    @onionhammer I thought it was (note queries part):

    queryConfig = {
      queries: {
        retry: (failures, err) => ...
      }
    }
    
  4. tannerlinsley commented on Jun 27, 2020

    @tannerlinsley
    Member

    That’s for your global config. If you are configuring at the query level, you don’t need to nest everything inside of the queries object

  5. tannerlinsley commented on Jun 28, 2020

    @tannerlinsley
    Member

    I can't replicate this, so it may just be an outdated types issue. Please reopen with more info if you'd like.

  6. onionhammer commented on Jun 29, 2020

    @onionhammer
    Author

    @tannerlinsley thanks for looking into it, I resolved this by removing any reference to @types/react-query. Looks like the combination of the latest version and the old type definition were causing this.

    Another potential issue I'm seeing though, with the new version, is that react-query seems to cache errored queries? so I get a 401 if my session expires, the query immediately fails without retrying, and then I sign in (the error boundary redirects me), but then it immediately re-throws the same error again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions