NextJS13 & URQL GraphQL Client --> Redirect in common error handler

181 Views Asked by At

I'm trying out a NextJS-14 Application. I'm using on the client side URQL as the GraphQL Client. The URQL Client is created on the root layout.

There you can define an error handler:

mapExchange({
  onError(error, operation) {
    console.log(`The operation ${operation.key} has errored with:`, error);
    // If Error === A --> Redirect to /login
  },
});

In this common error handler, I would like to redirect to a dedicated page.

I've tried is with useRouter().push("/...") or redirect("/...") (from next/navigation) In both cases, I received a RuntimeError.

useRouter() --> Hook not accessible outside the function

redirect() --> Unhandled Runtime Error Error: NEXT_REDIRECT

0

There are 0 best solutions below