Handling RPC Request Errors in React Query

Hello, is there a better way to do this so I can get the return value of the rpc request in my use-query and throw the error so that react query can catch it?

const { data } = useQuery({
    queryKey: ["news"],
    queryFn: async () => {
      const exit = await Runtime.runPromiseExit(
        RpcClient(
          new NewsRequest({
            page: 1,
          })
        )
      )

      return Exit.getOrElse(exit, (cause) => {
        if (Cause.isFailType(cause)) {
          throw cause.error
        }

        throw Cause.pretty(cause)
      })
    },
  })
Was this page helpful?