Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

shouldThrowError.md

45 lines1.1 KB

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```