Skip to content

Commit d426ea6

Browse files
committed
make sure errors in user provided callbacks are still handled properly
1 parent 4513bbf commit d426ea6

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -809,23 +809,27 @@ export function buildThunks<
809809
caughtError = e
810810
}
811811
}
812-
if (caughtError instanceof NamedSchemaError) {
813-
const info: SchemaFailureInfo = {
814-
endpoint: arg.endpointName,
815-
arg: arg.originalArgs,
816-
type: arg.type,
817-
queryCacheKey: arg.type === 'query' ? arg.queryCacheKey : undefined,
818-
}
819-
endpointDefinition.onSchemaFailure?.(caughtError, info)
820-
onSchemaFailure?.(caughtError, info)
821-
const { catchSchemaFailure = globalCatchSchemaFailure } =
822-
endpointDefinition
823-
if (catchSchemaFailure) {
824-
return rejectWithValue(
825-
catchSchemaFailure(caughtError, info),
826-
addShouldAutoBatch({ baseQueryMeta: caughtError._bqMeta }),
827-
)
812+
try {
813+
if (caughtError instanceof NamedSchemaError) {
814+
const info: SchemaFailureInfo = {
815+
endpoint: arg.endpointName,
816+
arg: arg.originalArgs,
817+
type: arg.type,
818+
queryCacheKey: arg.type === 'query' ? arg.queryCacheKey : undefined,
819+
}
820+
endpointDefinition.onSchemaFailure?.(caughtError, info)
821+
onSchemaFailure?.(caughtError, info)
822+
const { catchSchemaFailure = globalCatchSchemaFailure } =
823+
endpointDefinition
824+
if (catchSchemaFailure) {
825+
return rejectWithValue(
826+
catchSchemaFailure(caughtError, info),
827+
addShouldAutoBatch({ baseQueryMeta: caughtError._bqMeta }),
828+
)
829+
}
828830
}
831+
} catch (e) {
832+
caughtError = e
829833
}
830834
if (
831835
typeof process !== 'undefined' &&

0 commit comments

Comments
 (0)