Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to display error message from grapqhl response in form #4346

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const CREATE_ACCOUNT = gql`
# eslint-disable-next-line @graphql-eslint/require-id-when-available
customer {
email
is_confirmed
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion packages/peregrine/lib/talons/FormError/useFormError.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ export const useFormError = props => {
defaultMessage:
'An error has occurred. Please check the input and try again.'
});
return deriveErrorMessage(errors, defaultErrorMessage);

const firstError = errors
.filter(error => error !== null || undefined)
.map(error => (Array.isArray(error) ? error[0] : error))
.find(message => message);
var graphqlErrorMessage;

if (firstError) {
graphqlErrorMessage = formatMessage({
id: 'formError.responseError',
defaultMessage: firstError.message
});
}

return graphqlErrorMessage
? deriveErrorMessage(errors, graphqlErrorMessage)
: deriveErrorMessage(errors, defaultErrorMessage);
}, [errors, formatMessage, allowErrorMessages]);

return {
Expand Down