Open History to see the last commit
1---
2id: CancelledError
3title: CancelledError
4---
5β
6Defined in: [packages/query-core/src/retryer.ts:120](https://github.com/TanStack/query/blob/main/packages/query-core/src/retryer.ts#L120)
7β
8The error thrown by a `Retryer` (and surfaced to `query.promise`/`mutation`) when a fetch is cancelled, e.g. via
9`query.cancel()`. `revert`, if `true`, tells the caller to restore the state the query was in before the fetch
10started instead of surfacing the error. `silent`, if `true`, tells the caller to suppress this error and instead
11resolve with the promise of the fetch that triggered the cancellation.
12β
13## Example
14β
15```ts
16query.cancel()
17β
18try {
19 await query.promise
20} catch (error) {
21 if (error instanceof CancelledError) {
22 // the fetch was cancelled, e.g. via `query.cancel()`
23 }
24}
25```
26β
27## Extends
28β
29- `Error`
30β
31## Constructors
32β
33### Constructor
34β
35```ts
36new CancelledError(options?: CancelOptions): CancelledError;
37```
38β
39Defined in: [packages/query-core/src/retryer.ts:123](https://github.com/TanStack/query/blob/main/packages/query-core/src/retryer.ts#L123)
40β
41#### Parameters
42β
43##### options?
44β
45[`CancelOptions`](../interfaces/CancelOptions.md)
46β
47#### Returns
48β
49`CancelledError`
50β
51#### Overrides
52β
53```ts
54Error.constructor
55```
56β
57## Properties
58β
59### cause?
60β
61```ts
62optional cause?: unknown;
63```
64β
65Defined in: node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24
66β
67#### Inherited from
68β
69```ts
70Error.cause
71```
72β
73***
74β
75### message
76β
77```ts
78message: string;
79```
80β
81Defined in: node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075
82β
83#### Inherited from
84β
85```ts
86Error.message
87```
88β
89***
90β
91### name
92β
93```ts
94name: string;
95```
96β
97Defined in: node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074
98β
99#### Inherited from
100β
101```ts
102Error.name
103```
104β
105***
106β
107### revert?
108β
109```ts
110optional revert?: boolean;
111```
112β
113Defined in: [packages/query-core/src/retryer.ts:121](https://github.com/TanStack/query/blob/main/packages/query-core/src/retryer.ts#L121)
114β
115***
116β
117### silent?
118β
119```ts
120optional silent?: boolean;
121```
122β
123Defined in: [packages/query-core/src/retryer.ts:122](https://github.com/TanStack/query/blob/main/packages/query-core/src/retryer.ts#L122)
124β
125***
126β
127### stack?
128β
129```ts
130optional stack?: string;
131```
132β
133Defined in: node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076
134β
135#### Inherited from
136β
137```ts
138Error.stack
139```
140β
141***
142β
143### stackTraceLimit
144β
145```ts
146static stackTraceLimit: number;
147```
148β
149Defined in: node\_modules/.pnpm/@types+node@22.19.15/node\_modules/@types/node/globals.d.ts:68
150β
151The `Error.stackTraceLimit` property specifies the number of stack frames
152collected by a stack trace (whether generated by `new Error().stack` or
153`Error.captureStackTrace(obj)`).
154β
155The default value is `10` but may be set to any valid JavaScript number. Changes
156will affect any stack trace captured _after_ the value has been changed.
157β
158If set to a non-number value, or set to a negative number, stack traces will
159not capture any frames.
160β
161#### Inherited from
162β
163```ts
164Error.stackTraceLimit
165```
166β
167## Methods
168β
169### captureStackTrace()
170β
171```ts
172static captureStackTrace(targetObject: object, constructorOpt?: Function): void;
173```
174β
175Defined in: node\_modules/.pnpm/@types+node@22.19.15/node\_modules/@types/node/globals.d.ts:52
176β
177Creates a `.stack` property on `targetObject`, which when accessed returns
178a string representing the location in the code at which
179`Error.captureStackTrace()` was called.
180β
181```js
182const myObject = {};
183Error.captureStackTrace(myObject);
184myObject.stack; // Similar to `new Error().stack`
185```
186β
187The first line of the trace will be prefixed with
188`${myObject.name}: ${myObject.message}`.
189β
190The optional `constructorOpt` argument accepts a function. If given, all frames
191above `constructorOpt`, including `constructorOpt`, will be omitted from the
192generated stack trace.
193β
194The `constructorOpt` argument is useful for hiding implementation
195details of error generation from the user. For instance:
196β
197```js
198function a() {
199 b();
200}
201β
202function b() {
203 c();
204}
205β
206function c() {
207 // Create an error without stack trace to avoid calculating the stack trace twice.
208 const { stackTraceLimit } = Error;
209 Error.stackTraceLimit = 0;
210 const error = new Error();
211 Error.stackTraceLimit = stackTraceLimit;
212β
213 // Capture the stack trace above function b
214 Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
215 throw error;
216}
217β
218a();
219```
220β
221#### Parameters
222β
223##### targetObject
224β
225`object`
226β
227##### constructorOpt?
228β
229`Function`
230β
231#### Returns
232β
233`void`
234β
235#### Inherited from
236β
237```ts
238Error.captureStackTrace
239```
240β
241***
242β
243### prepareStackTrace()
244β
245```ts
246static prepareStackTrace(err: Error, stackTraces: CallSite[]): any;
247```
248β
249Defined in: node\_modules/.pnpm/@types+node@22.19.15/node\_modules/@types/node/globals.d.ts:56
250β
251#### Parameters
252β
253##### err
254β
255`Error`
256β
257##### stackTraces
258β
259`CallSite`[]
260β
261#### Returns
262β
263`any`
264β
265#### See
266β
267https://v8.dev/docs/stack-trace-api#customizing-stack-traces
268β
269#### Inherited from
270β
271```ts
272Error.prepareStackTrace
273```