Skip to content

Commit

Permalink
Added code to display error message from grapqhl response in form (#4346
Browse files Browse the repository at this point in the history
)

* Added code to display error message from grapqhl response in form

* Prettier check changes

* Changed PWA flow as per the pwa backend repo code
  • Loading branch information
del22123 authored Jan 15, 2025
1 parent bcfd173 commit c1a282c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit c1a282c

Please sign in to comment.