Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TError always unknown #147

Closed
Alexandre-Cornillon opened this issue Sep 5, 2024 · 2 comments
Closed

TError always unknown #147

Alexandre-Cornillon opened this issue Sep 5, 2024 · 2 comments

Comments

@Alexandre-Cornillon
Copy link

Describe the bug

Hello,
When we use the TError type from codegen, the type is always unknown.
How to have the payload or message of all the 400s and 500s errors typed ?
Thanks

To Reproduce
Steps to reproduce the behavior:
npx --package @7nohe/openapi-react-query-codegen openapi-rq -i https://petstore.swagger.io/v2/swagger.json -o src/generated

OpenAPI spec file
https://petstore.swagger.io/v2/swagger.json

Expected behavior
I need to have the content or message of all the 400s and 500s errors.

Screenshots
Screenshot 2024-09-05 at 17 45 16

  • OS: macOS
  • Version: Sonoma 14.5

Additional context
Add any other context about the problem here.

@w00kie
Copy link

w00kie commented Oct 3, 2024

Facing the same issue, I don't know how to use error message in my returned data with the onError method.

My openapi.yml has definitions for error objects returned on 400 error code and these are picked up in the types.gen.ts file but I don't see how to use them in my mutate hooks.

@7nohe
Copy link
Owner

7nohe commented Oct 14, 2024

From v2, TError is now typed.

export const useFindPets = <
  TData = Common.FindPetsDefaultResponse,
  TError = FindPetsError,
  TQueryKey extends Array<unknown> = unknown[],
>(
  clientOptions: Options<FindPetsData, true> = {},
  queryKey?: TQueryKey,
  options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
  useQuery<TData, TError>({
    queryKey: Common.UseFindPetsKeyFn(clientOptions, queryKey),
    queryFn: () =>
      findPets({ ...clientOptions }).then(
        (response) => response.data as TData,
      ) as TData,
    ...options,
  });

@7nohe 7nohe closed this as completed Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants