Skip to content

Commit

Permalink
Merge pull request #3415 from marmelab/improve-reference-array-input-…
Browse files Browse the repository at this point in the history
…error-msg

[RFR] Improve ReferenceArrayInput error message when given bad data
  • Loading branch information
fzaninotto authored Jul 19, 2019
2 parents 0e75a4e + 300af45 commit 45130f7
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,23 @@ const makeMapStateToProps = () =>
[
getReferenceResource,
getPossibleReferenceValues,
(_, { input: { value: referenceIds } }) => referenceIds || [],
(_, { resource, input }) => {
const { value: referenceIds } = input;

if (!referenceIds) {
return [];
}

if (Array.isArray(referenceIds)) {
return referenceIds;
}

throw new Error(
`<ReferenceArrayInput> expects value to be an array, but the value passed as '${resource}.${
input.name
}' is type '${typeof referenceIds}': ${referenceIds}`
);
},
],
(referenceState, possibleValues, inputIds) => ({
matchingReferences: getPossibleReferences(
Expand Down

0 comments on commit 45130f7

Please sign in to comment.