aws-amplify / aws-amplify/amplify-codegen-ui

Generated CreateForm: Catch statement throws an error itself (Handle graphql errors properly)

Open
#1,168 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
31
Forks
30
PR merge metrics
No merged PRs in 30d

Description

### Problem:

onSubmit handler has a `catch` block:

`
} catch (err) {
if (onError) {
const messages = err.errors.map((e) => e.message).join("\n");
onError(modelFields, messages);
}
}
`

err does not necessarily have an `errors` attribute, which will result in an error thrown: `TypeError: Cannot read properties of undefined (reading 'map')`.

Contributor guide

Open the contributing guide

Research direction

Locate the generated CreateForm onSubmit handler and inspect its catch block. Reproduce an error without an errors attribute and verify it no longer causes a secondary TypeError, while GraphQL errors still reach onError with their messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, react, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.