Open History to see the last commit
1---
2id: shouldThrowError
3title: shouldThrowError
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8```ts
9function shouldThrowError<T extends (...args: any[]) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
10```
11β
12Defined in: [packages/query-core/src/utils.ts:693](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L693)
13β
14Resolves a `throwOnError` option to a boolean.
15If `throwOnError` is a function, it is called with `params` (e.g. the error and, depending on the caller,
16additional context such as the query or mutation) and its result is returned, allowing the throwing
17behavior to be decided per error. Otherwise, `throwOnError` itself is coerced to a boolean (`undefined`
18resolves to `false`).
19β
20## Type Parameters
21β
22### T
23β
24`T` *extends* (...`args`: `any`[]) => `boolean`
25β
26## Parameters
27β
28### throwOnError
29β
30`boolean` \| `T` \| `undefined`
31β
32The `throwOnError` option: a boolean, a function that decides per error, or
33`undefined`.
34β
35### params
36β
37`Parameters`\<`T`\>
38β
39The arguments passed to `throwOnError` if it is a function.
40β
41## Returns
42β
43`boolean`
44β
45Whether the error should be thrown.
46β
47## Example
48β
49```ts
50const throwOnError =
51 query.state.error && typeof options.throwOnError === 'function'
52 ? shouldThrowError(options.throwOnError, [query.state.error, query])
53 : options.throwOnError
54```