Skip to content

Commit 79d1dec

Browse files
committed
docs
1 parent 84e31a5 commit 79d1dec

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

docs/rtk-query/api/createApi.mdx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,16 @@ If you specify `track: false` when manually dispatching queries, RTK Query will
493493
You can set this globally in `createApi`, but you can also override the default value and have more granular control by passing `onSchemaFailure` to each individual endpoint definition.
494494
:::
495495

496+
### `catchSchemaFailure`
497+
498+
[summary](docblock://query/createApi.ts?token=CreateApiOptions.catchSchemaFailure)
499+
500+
[examples](docblock://query/createApi.ts?token=CreateApiOptions.catchSchemaFailure)
501+
502+
:::note
503+
You can set this globally in `createApi`, but you can also override the default value and have more granular control by passing `catchSchemaFailure` to each individual endpoint definition.
504+
:::
505+
496506
### `skipSchemaValidation`
497507

498508
[summary](docblock://query/createApi.ts?token=CreateApiOptions.skipSchemaValidation)
@@ -832,7 +842,23 @@ Endpoints can have schemas for runtime validation of various values. Any [Standa
832842

833843
:::warning
834844

835-
Schema failures are treated as _fatal_, meaning that normal error handling such as tag invalidation will not be executed.
845+
By default, schema failures are treated as _fatal_, meaning that normal error handling such as tag invalidation will not be executed.
846+
847+
In order for schema failures to be treated as non-fatal, you must provide a [`catchSchemaFailure`](#catchschemafailure) function, to convert the schema failure into an error shape matching the base query errors.
848+
849+
```ts title="catchSchemaFailure example" no-transpile
850+
const api = createApi({
851+
baseQuery: fetchBaseQuery({ baseUrl: '/' }),
852+
catchSchemaFailure: (error, info) => ({
853+
status: 'CUSTOM_ERROR',
854+
error: error.schemaName + ' failed validation',
855+
data: error,
856+
}),
857+
endpoints: (build) => ({
858+
// ...
859+
}),
860+
})
861+
```
836862

837863
:::
838864

packages/toolkit/src/query/createApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ export interface CreateApiOptions<
271271
* data: error.issues,
272272
* }),
273273
* })
274+
* ```
274275
*/
275276
catchSchemaFailure?: SchemaFailureConverter<BaseQuery>
276277

0 commit comments

Comments
 (0)