Skip to content

Commit

Permalink
5/n - Add erroring on seeing relayFieldErrors
Browse files Browse the repository at this point in the history
Reviewed By: tyao1

Differential Revision: D51944692

fbshipit-source-id: ef0afb0cecbf87228ec2aec283a9754d52b028d1
  • Loading branch information
itamark authored and facebook-github-bot committed Jan 22, 2024
1 parent 982be71 commit 27a0623
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/relay-runtime/util/handlePotentialSnapshotErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
RelayResolverErrors,
} from '../store/RelayStoreTypes';

import {RelayFieldError} from '../store/RelayErrorTrie';
import RelayFeatureFlags from './RelayFeatureFlags';

function handlePotentialSnapshotErrors(
Expand All @@ -34,7 +35,10 @@ function handlePotentialSnapshotErrors(
error: resolverError.error,
});
}
if (RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING) {
if (
RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING &&
errorResponseFields != null
) {
if (errorResponseFields != null) {
for (const fieldError of errorResponseFields) {
const {path, owner, error} = fieldError;
Expand All @@ -47,6 +51,13 @@ function handlePotentialSnapshotErrors(
});
}
}

if (RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING_THROW_BY_DEFAULT) {
throw new RelayFieldError(
`Relay: Unexpected response payload - this object includes an errors property in which you can access the underlying errors`,
errorResponseFields.map(({path, owner, error}) => error),
);
}
}

if (missingRequiredFields != null) {
Expand Down

0 comments on commit 27a0623

Please sign in to comment.