Skip to content

Errors from createServerFn is being wrapped and tanstack/query is receiving that error. #2238

Closed

Description

@jadedevin13

I wish to transform the errors coming from createServerFn. Those are actually zod validation errors that are server-side.

export const objectUpsertOptions: UseMutationOptions<
  void,
  void,
  z.infer<typeof upsertParamsSchema>
> = {
  mutationKey: ['objectUpsert'],
  mutationFn: objectUpsert,
  onSuccess: (data, variables, context) => {
    queryClient.invalidateQueries({ queryKey: ['objects'] })
  },
  onError: (error, variables, context) => {
    console.log(SuperJSON.stringify(error) as string)
    toast.error(SuperJSON.stringify(error) as string)
  },
}

Unfortunately, in the fetcher

throw new Error(
[
`Request failed with status ${response.status}`,
`${JSON.stringify(body, null, 2)}`,
].join('\n\n'),
)

The response is being wrapped, is there a way to expose the JSON body and not have a string with a concatenated prefix of "Request failed with status 500"

Image

Activity

  1. SeanCassiere commented on Sep 3, 2024

    @SeanCassiere
    Member

    @jadedevin13 With the 1.53.0 release you'll need to JSON.parse the Error.message, but it should be much easier now to read what's being returned.

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

    enhancementNew feature or requeststartEverything about TanStack Start

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions