Skip to content

Commit 4af125d

Browse files
committed
introduce handleRawError
to include filtering
1 parent c3398d5 commit 4af125d

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/execution/execute.ts

+23-15
Original file line numberDiff line numberDiff line change
@@ -704,16 +704,14 @@ function executeField(
704704

705705
result = resolveFn(source, args, contextValue, info);
706706
} catch (rawError) {
707-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
708-
const handledError = addError(
707+
return handleRawError(
709708
rawError,
709+
exeContext,
710710
fieldNodes,
711711
returnType,
712712
path,
713-
errors,
713+
asyncPayloadRecord,
714714
);
715-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
716-
return handledError;
717715
}
718716

719717
if (isPromise(result)) {
@@ -766,6 +764,20 @@ export function buildResolveInfo(
766764
};
767765
}
768766

767+
function handleRawError(
768+
rawError: unknown,
769+
exeContext: ExecutionContext,
770+
fieldNodes: ReadonlyArray<FieldNode>,
771+
returnType: GraphQLOutputType,
772+
path: Path,
773+
asyncPayloadRecord: AsyncPayloadRecord | undefined,
774+
): null {
775+
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
776+
addError(rawError, fieldNodes, returnType, path, errors);
777+
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
778+
return null;
779+
}
780+
769781
function addError(
770782
rawError: unknown,
771783
fieldNodes: ReadonlyArray<FieldNode>,
@@ -927,16 +939,14 @@ async function completePromiseCatchingErrors(
927939
}
928940
return completed;
929941
} catch (rawError) {
930-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
931-
const handledError = addError(
942+
return handleRawError(
932943
rawError,
944+
exeContext,
933945
fieldNodes,
934946
returnType,
935947
path,
936-
errors,
948+
asyncPayloadRecord,
937949
);
938-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
939-
return handledError;
940950
}
941951
}
942952

@@ -961,16 +971,14 @@ function completeValueCatchingErrors(
961971
asyncPayloadRecord,
962972
);
963973
} catch (rawError) {
964-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
965-
const handledError = addError(
974+
return handleRawError(
966975
rawError,
976+
exeContext,
967977
fieldNodes,
968978
returnType,
969979
path,
970-
errors,
980+
asyncPayloadRecord,
971981
);
972-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
973-
return handledError;
974982
}
975983

976984
if (isPromise(completedValue)) {

0 commit comments

Comments
 (0)