Closed Alexandre-Cornillon closed 1 month ago
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.
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,
});
Describe the bug
Hello, When we use the
TError
type from codegen, the type is alwaysunknown
. How to have the payload or message of all the 400s and 500s errors typed ? ThanksTo 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
Additional context Add any other context about the problem here.