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