Skip to content

Add a default retry handling to avoid retry on specific TRCP errors #1714

Closed as not planned

Description

@ArnaudBarre

I just found that with default settings when using the react client, the query is retried 3 times despite the server sending an UNAUTHORIZED error. I think a default could be to only retry in this cases:

PARSE_ERROR: false
BAD_REQUEST: false
INTERNAL_SERVER_ERROR: ?
UNAUTHORIZED: false
FORBIDDEN: false
NOT_FOUND: false
METHOD_NOT_SUPPORTED: false
TIMEOUT: true
PRECONDITION_FAILED: false
PAYLOAD_TOO_LARGE: false
CLIENT_CLOSED_REQUEST: true

I can create a PR if you agree on the general idea

Activity

  1. jlalmes commented on Mar 30, 2022

    @jlalmes
    Contributor

    Like this idea, I'm also not sure how to best handle retrying after an INTERNAL_SERVER_ERROR error.

  2. KATT commented on Apr 1, 2022

    @KATT
    Member

    I think I don't want it in the library, but I want the examples to showcase a production-ready version, so it would be good to have some more sensible defaults in here: https://github.com/trpc/trpc/blob/main/examples/next-prisma-starter/src/pages/_app.tsx#L74

  3. KATT commented on Apr 1, 2022

    @KATT
    Member

    Idea:

              queries: {
                retry(failureCount, _err) {
                  const err = _err as never as TRPCClientErrorLike<AppRouter>;
                  const MAX_QUERY_RETRIES = 3;
    
                  const code = err?.data?.code;
                  if (code === 'NOT_FOUND' || code === 'BAD_REQUEST') {
                    // prevent refetch on queries that always will fail
                    return false;
                  }
                  return failureCount < MAX_QUERY_RETRIES;
                },
              },
  4. ViktorQvarfordt commented on Jul 30, 2022

    @ViktorQvarfordt

    The default behavior of retrying on error is strange to me. Most errors don't resolve automatically. The only error I can think of that should be retried is if the network connection was interrupted.

    The current mechanism is problematic for a user since they have to wait for all retries to fail until the app can show the error. This is clearly not desired for errors like 400 Bad request, 401 Unauthorized, 404 Not found. In these cases, we'd rather show the user directly what the problem was so that they can fix it.

  5. ViktorQvarfordt commented on Jul 30, 2022

    @ViktorQvarfordt

    Is it possible to completely disable the retry mechanism until something more flexible is put in place?

  6. KATT commented on Jul 30, 2022

    @KATT
    Member

    See the message above, you can customize the behavior fully

  7. added
    📚 documentation / examples
    on Jul 30, 2022
  8. ArnaudBarre commented on Jul 30, 2022

    @ArnaudBarre
    Author

    Yes it's easy do disable react-query behaviour. For now I ended up using:

    new QueryClient({ defaultOptions: { queries: { retry: false } } })
  9. github-actions commented on Oct 4, 2022

    @github-actions
    Contributor

    This issue has been locked because it had no new activity for 14 days. If you are running into a similar issue, please create a new issue. Thank you.

  10. locked as resolved and limited conversation to collaborators on Oct 4, 2022
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

    💡 ideas📚 documentation / examples

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions