Skip to content

Commit 7575d65

Browse files
committed
introduce handleRawError
to include filtering
1 parent 4450aa5 commit 7575d65

File tree

1 file changed

+50
-42
lines changed

1 file changed

+50
-42
lines changed

src/execution/execute.ts

Lines changed: 50 additions & 42 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+
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)) {
@@ -751,32 +749,32 @@ function completePromiseCatchingErrors(
751749
result: Promise<unknown>,
752750
asyncPayloadRecord?: AsyncPayloadRecord,
753751
): Promise<unknown> {
754-
return result
755-
.then((resolved) =>
756-
completeValue(
757-
exeContext,
758-
returnType,
759-
fieldNodes,
760-
info,
761-
path,
762-
resolved,
763-
asyncPayloadRecord,
764-
),
765-
)
766-
.then(undefined, (rawError) => {
752+
return (
753+
result
754+
.then((resolved) =>
755+
completeValue(
756+
exeContext,
757+
returnType,
758+
fieldNodes,
759+
info,
760+
path,
761+
resolved,
762+
asyncPayloadRecord,
763+
),
764+
)
767765
// Note: we don't rely on a `catch` method, but we do expect "thenable"
768766
// to take a second callback for the error case.
769-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
770-
const handledError = addError(
771-
rawError,
772-
fieldNodes,
773-
returnType,
774-
path,
775-
errors,
776-
);
777-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
778-
return handledError;
779-
});
767+
.then(undefined, (rawError) =>
768+
handleRawError(
769+
rawError,
770+
exeContext,
771+
fieldNodes,
772+
returnType,
773+
path,
774+
asyncPayloadRecord,
775+
),
776+
)
777+
);
780778
}
781779

782780
function completeValueCatchingErrors(
@@ -800,33 +798,29 @@ function completeValueCatchingErrors(
800798
asyncPayloadRecord,
801799
);
802800
} catch (rawError) {
803-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
804-
const handledError = addError(
801+
return handleRawError(
805802
rawError,
803+
exeContext,
806804
fieldNodes,
807805
returnType,
808806
path,
809-
errors,
807+
asyncPayloadRecord,
810808
);
811-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
812-
return handledError;
813809
}
814810

815811
if (isPromise(completedItem)) {
816812
// Note: we don't rely on a `catch` method, but we do expect "thenable"
817813
// to take a second callback for the error case.
818-
completedItem = completedItem.then(undefined, (rawError) => {
819-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
820-
const handledError = addError(
814+
completedItem = completedItem.then(undefined, (rawError) =>
815+
handleRawError(
821816
rawError,
817+
exeContext,
822818
fieldNodes,
823819
returnType,
824820
path,
825-
errors,
826-
);
827-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
828-
return handledError;
829-
});
821+
asyncPayloadRecord,
822+
),
823+
);
830824
}
831825
return completedItem;
832826
}
@@ -858,6 +852,20 @@ export function buildResolveInfo(
858852
};
859853
}
860854

855+
function handleRawError(
856+
rawError: unknown,
857+
exeContext: ExecutionContext,
858+
fieldNodes: ReadonlyArray<FieldNode>,
859+
returnType: GraphQLOutputType,
860+
path: Path,
861+
asyncPayloadRecord: AsyncPayloadRecord | undefined,
862+
): null {
863+
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
864+
addError(rawError, fieldNodes, returnType, path, errors);
865+
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
866+
return null;
867+
}
868+
861869
function addError(
862870
rawError: unknown,
863871
fieldNodes: ReadonlyArray<FieldNode>,

0 commit comments

Comments
 (0)