Skip to content

Commit 1aa20f6

Browse files
committed
docs
1 parent 84e31a5 commit 1aa20f6

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

docs/rtk-query/api/createApi.mdx

+27-1
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

0 commit comments

Comments
 (0)