Skip to content

Commit 764cbd5

Browse files
committed
add tests for catchSchemaFailure
1 parent 6430af6 commit 764cbd5

File tree

4 files changed

+341
-12
lines changed

4 files changed

+341
-12
lines changed

packages/toolkit/src/query/core/buildThunks.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -771,19 +771,18 @@ export function buildThunks<
771771

772772
let { value, meta } = caughtError
773773

774-
if (rawErrorResponseSchema && !skipSchemaValidation) {
775-
value = await parseWithSchema(
776-
rawErrorResponseSchema,
777-
value,
778-
'rawErrorResponseSchema',
779-
)
780-
}
781-
782-
if (metaSchema && !skipSchemaValidation) {
783-
meta = await parseWithSchema(metaSchema, meta, 'metaSchema')
784-
}
785-
786774
try {
775+
if (rawErrorResponseSchema && !skipSchemaValidation) {
776+
value = await parseWithSchema(
777+
rawErrorResponseSchema,
778+
value,
779+
'rawErrorResponseSchema',
780+
)
781+
}
782+
783+
if (metaSchema && !skipSchemaValidation) {
784+
meta = await parseWithSchema(metaSchema, meta, 'metaSchema')
785+
}
787786
let transformedErrorResponse = await transformErrorResponse(
788787
value,
789788
meta,

packages/toolkit/src/query/endpointDefinitions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ interface CommonEndpointDefinition<
385385
* ```
386386
*/
387387
onSchemaFailure?: SchemaFailureHandler
388+
388389
/**
389390
* Convert a schema validation failure into an error shape matching base query errors.
390391
*

packages/toolkit/src/query/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export type {
4747
TagTypesFromApi,
4848
UpdateDefinitions,
4949
SchemaFailureHandler,
50+
SchemaFailureConverter,
5051
SchemaFailureInfo,
5152
} from './endpointDefinitions'
5253
export { fetchBaseQuery } from './fetchBaseQuery'

0 commit comments

Comments
 (0)