Skip to content

Commit

Permalink
Improve ReferenceArrayInput error message when given bad data
Browse files Browse the repository at this point in the history
When passing a bad value to a ReferenceArrayInput, we have a cryptic
error message.
Now, we explain what data was badly formatted an its location.
  • Loading branch information
Kmaschta committed Jul 15, 2019
1 parent 6e2cc49 commit 09f0fef
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,26 @@ const makeMapStateToProps = () =>
[
getReferenceResource,
getPossibleReferenceValues,
(_, { input: { value: referenceIds } }) => referenceIds || [],
(_, { resource, input }) => {
const { value: referenceIds } = input;

if (
referenceIds === null ||
typeof referenceIds === 'undefined'
) {
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 09f0fef

Please sign in to comment.