Skip to content

Commit 3802af7

Browse files
committed
extract handleFieldError function
1 parent c52afaa commit 3802af7

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/execution/execute.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -814,34 +814,27 @@ function completeValueCatchingError(
814814
// to take a second callback for the error case.
815815
return completed.then(undefined, rawError => {
816816
const error = locatedFieldError(rawError, fieldNodes, path);
817-
818-
// If the field type is non-nullable, then it is resolved without any
819-
// protection from errors, however it still properly locates the error.
820-
if (isNonNullType(returnType)) {
821-
throw error;
822-
}
823-
824-
// Otherwise, error protection is applied, logging the error and
825-
// resolving a null value for this field if one is encountered.
826-
exeContext.errors.push(error);
827-
return null;
817+
return handleFieldError(error, returnType, exeContext);
828818
});
829819
}
830820
return completed;
831821
} catch (rawError) {
832822
const error = locatedFieldError(rawError, fieldNodes, path);
823+
return handleFieldError(error, returnType, exeContext);
824+
}
825+
}
833826

834-
// If the field type is non-nullable, then it is resolved without any
835-
// protection from errors, however it still properly locates the error.
836-
if (isNonNullType(returnType)) {
837-
throw error;
838-
}
839-
840-
// Otherwise, error protection is applied, logging the error and resolving
841-
// a null value for this field if one is encountered.
842-
exeContext.errors.push(error);
843-
return null;
827+
function handleFieldError(error, returnType, exeContext) {
828+
// If the field type is non-nullable, then it is resolved without any
829+
// protection from errors, however it still properly locates the error.
830+
if (isNonNullType(returnType)) {
831+
throw error;
844832
}
833+
834+
// Otherwise, error protection is applied, logging the error and resolving
835+
// a null value for this field if one is encountered.
836+
exeContext.errors.push(error);
837+
return null;
845838
}
846839

847840
function locatedFieldError(errorValue, fieldNodes, path) {

0 commit comments

Comments
 (0)