Skip to content

Commit 70d4963

Browse files
committed
introduce handleRawError
to include filtering
1 parent 9bc7280 commit 70d4963

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
@@ -703,16 +703,14 @@ function executeField(
703703

704704
result = resolveFn(source, args, contextValue, info);
705705
} catch (rawError) {
706-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
707-
const handledError = addError(
706+
return handleRawError(
708707
rawError,
708+
exeContext,
709709
fieldNodes,
710710
returnType,
711711
path,
712-
errors,
712+
asyncPayloadRecord,
713713
);
714-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
715-
return handledError;
716714
}
717715

718716
if (isPromise(result)) {
@@ -765,6 +763,20 @@ export function buildResolveInfo(
765763
};
766764
}
767765

766+
function handleRawError(
767+
rawError: unknown,
768+
exeContext: ExecutionContext,
769+
fieldNodes: ReadonlyArray<FieldNode>,
770+
returnType: GraphQLOutputType,
771+
path: Path,
772+
asyncPayloadRecord: AsyncPayloadRecord | undefined,
773+
): null {
774+
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
775+
addError(rawError, fieldNodes, returnType, path, errors);
776+
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
777+
return null;
778+
}
779+
768780
function addError(
769781
rawError: unknown,
770782
fieldNodes: ReadonlyArray<FieldNode>,
@@ -926,16 +938,14 @@ async function completePromiseCatchingErrors(
926938
}
927939
return completed;
928940
} catch (rawError) {
929-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
930-
const handledError = addError(
941+
return handleRawError(
931942
rawError,
943+
exeContext,
932944
fieldNodes,
933945
returnType,
934946
path,
935-
errors,
947+
asyncPayloadRecord,
936948
);
937-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
938-
return handledError;
939949
}
940950
}
941951

@@ -960,16 +970,14 @@ function completeValueCatchingErrors(
960970
asyncPayloadRecord,
961971
);
962972
} catch (rawError) {
963-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
964-
const handledError = addError(
973+
return handleRawError(
965974
rawError,
975+
exeContext,
966976
fieldNodes,
967977
returnType,
968978
path,
969-
errors,
979+
asyncPayloadRecord,
970980
);
971-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
972-
return handledError;
973981
}
974982

975983
if (isPromise(completedValue)) {

0 commit comments

Comments
 (0)