Skip to content

Commit e1074d8

Browse files
committed
introduce handleRawError
to include filtering
1 parent 09ed033 commit e1074d8

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/execution/execute.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -707,16 +707,14 @@ function executeField(
707707

708708
result = resolveFn(source, args, contextValue, info);
709709
} catch (rawError) {
710-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
711-
const handledError = addError(
710+
return handleRawError(
712711
rawError,
712+
exeContext,
713713
fieldNodes,
714714
returnType,
715715
path,
716-
errors,
716+
asyncPayloadRecord,
717717
);
718-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
719-
return handledError;
720718
}
721719

722720
if (isPromise(result)) {
@@ -769,6 +767,20 @@ export function buildResolveInfo(
769767
};
770768
}
771769

770+
function handleRawError(
771+
rawError: unknown,
772+
exeContext: ExecutionContext,
773+
fieldNodes: ReadonlyArray<FieldNode>,
774+
returnType: GraphQLOutputType,
775+
path: Path,
776+
asyncPayloadRecord: AsyncPayloadRecord | undefined,
777+
): null {
778+
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
779+
addError(rawError, fieldNodes, returnType, path, errors);
780+
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
781+
return null;
782+
}
783+
772784
function addError(
773785
rawError: unknown,
774786
fieldNodes: ReadonlyArray<FieldNode>,
@@ -930,16 +942,14 @@ async function completePromiseCatchingErrors(
930942
}
931943
return completed;
932944
} catch (rawError) {
933-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
934-
const handledError = addError(
945+
return handleRawError(
935946
rawError,
947+
exeContext,
936948
fieldNodes,
937949
returnType,
938950
path,
939-
errors,
951+
asyncPayloadRecord,
940952
);
941-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
942-
return handledError;
943953
}
944954
}
945955

@@ -964,16 +974,14 @@ function completeValueCatchingErrors(
964974
asyncPayloadRecord,
965975
);
966976
} catch (rawError) {
967-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
968-
const handledError = addError(
977+
return handleRawError(
969978
rawError,
979+
exeContext,
970980
fieldNodes,
971981
returnType,
972982
path,
973-
errors,
983+
asyncPayloadRecord,
974984
);
975-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
976-
return handledError;
977985
}
978986

979987
if (isPromise(completedValue)) {

0 commit comments

Comments
 (0)