openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

How to configure throwOnError for @tanstack/react-query

Open DavidVollmers opened this issue 3 months ago • 2 comments

Hey, I am struggling to understand how I can configure throwOnError when using the @tanstack/react-query plugin.

In tanstack react-query the default value of throwOnError is false but when generating query options using hey-api cli I get the following code generated:

export const xxxGetOptions = (options?: Options<xxxData>) => {
    return queryOptions({
        queryFn: async ({ queryKey, signal }) => {
            const { data } = await xxxGet({
                ...options,
                ...queryKey[0],
                signal,
                throwOnError: true
            });
            return data;
        },
        queryKey: xxxGetQueryKey(options)
    });
};

which always sets throwOnError to true. There seems to be no way to override this.

DavidVollmers avatar Oct 07 '25 09:10 DavidVollmers

Hi @DavidVollmers! I'm Dosu and I’m helping the openapi-ts team.

The generated query options for @tanstack/react-query via hey-api CLI always set throwOnError: true and there isn't a documented way to override this in the plugin or CLI configuration. This behavior is hardcoded in the generated query function, and the documentation only mentions customizing naming and casing—not error handling options like throwOnError for this plugin reference.

If you need to change this, you can manually edit the generated code to set throwOnError: false, or wrap the generated query function in your own utility that sets the desired value. Keep an eye on the documentation or changelogs for future updates in case this becomes configurable.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar Oct 07 '25 09:10 dosubot[bot]

any updates here? the recommendation to edit generated code manually seems like a bad joke...

DavidVollmers avatar Oct 21 '25 18:10 DavidVollmers