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

shouldThrowError.md

54 lines1.4 KB

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:691](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L691)
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```