Skip to content

Commit 84e31a5

Browse files
committed
include bqMeta on error so we can use it
1 parent 764cbd5 commit 84e31a5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ export function buildThunks<
573573
argSchema,
574574
finalQueryArg,
575575
'argSchema',
576+
{}, // we don't have a meta yet, so we can't pass it
576577
)
577578
}
578579

@@ -636,6 +637,7 @@ export function buildThunks<
636637
rawResponseSchema,
637638
result.data,
638639
'rawResponseSchema',
640+
result.meta,
639641
)
640642
}
641643

@@ -650,6 +652,7 @@ export function buildThunks<
650652
responseSchema,
651653
transformedResponse,
652654
'responseSchema',
655+
result.meta,
653656
)
654657
}
655658

@@ -747,6 +750,7 @@ export function buildThunks<
747750
metaSchema,
748751
finalQueryReturnValue.meta,
749752
'metaSchema',
753+
finalQueryReturnValue.meta,
750754
)
751755
}
752756

@@ -777,11 +781,12 @@ export function buildThunks<
777781
rawErrorResponseSchema,
778782
value,
779783
'rawErrorResponseSchema',
784+
meta,
780785
)
781786
}
782787

783788
if (metaSchema && !skipSchemaValidation) {
784-
meta = await parseWithSchema(metaSchema, meta, 'metaSchema')
789+
meta = await parseWithSchema(metaSchema, meta, 'metaSchema', meta)
785790
}
786791
let transformedErrorResponse = await transformErrorResponse(
787792
value,
@@ -793,6 +798,7 @@ export function buildThunks<
793798
errorResponseSchema,
794799
transformedErrorResponse,
795800
'errorResponseSchema',
801+
meta,
796802
)
797803
}
798804

@@ -816,7 +822,7 @@ export function buildThunks<
816822
if (catchSchemaFailure) {
817823
return rejectWithValue(
818824
catchSchemaFailure(caughtError, info),
819-
addShouldAutoBatch({ baseQueryMeta: {} }), // TODO: how do we get meta here?
825+
addShouldAutoBatch({ baseQueryMeta: caughtError._bqMeta }),
820826
)
821827
}
822828
}

packages/toolkit/src/query/standardSchema.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class NamedSchemaError extends SchemaError {
66
issues: readonly StandardSchemaV1.Issue[],
77
public readonly value: any,
88
public readonly schemaName: string,
9+
public readonly _bqMeta: any,
910
) {
1011
super(issues)
1112
}
@@ -15,10 +16,11 @@ export async function parseWithSchema<Schema extends StandardSchemaV1>(
1516
schema: Schema,
1617
data: unknown,
1718
schemaName: string,
19+
bqMeta: any,
1820
): Promise<StandardSchemaV1.InferOutput<Schema>> {
1921
const result = await schema['~standard'].validate(data)
2022
if (result.issues) {
21-
throw new NamedSchemaError(result.issues, data, schemaName)
23+
throw new NamedSchemaError(result.issues, data, schemaName, bqMeta)
2224
}
2325
return result.value
2426
}

0 commit comments

Comments
 (0)