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:582](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L582)
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β
30### params
31β
32`Parameters`\<`T`\>
33β
34## Returns
35β
36`boolean`
37β
38## Example
39β
40```ts
41const throwOnError =
42 query.state.error && typeof options.throwOnError === 'function'
43 ? shouldThrowError(options.throwOnError, [query.state.error, query])
44 : options.throwOnError
45```