-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: DAH-2565 Create Account Errors #2285
Conversation
adbf0b1
to
ef3c33a
Compare
e337400
to
0349ff2
Compare
) { | ||
if (error?.response?.data?.errors?.firstName) { | ||
// In the case that the name contains invalid characters (http, www, .), we will show the generic server error | ||
if (error.response.data?.errors?.full_messages.includes("Firstname is empty")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the complexity is coming from a lot of duplicated logic, so the logic can instead be reused for each error type
As just an example, could instead be something like:
export const handleNameServerErrors = (
key: string,
error: AxiosError<{
errors: {
email: string[]
password: string[]
DOB: string[]
full_messages: string[]
firstName: string[]
lastName: string[]
}
}>
) => {
if (error?.response?.status === 422 && error?.response?.data?.errors?.full_messages.length > 0) {
if (error?.response?.data?.errors?.[key]) {
// In the case that the name contains invalid characters (http, www, .), we will show the generic server error
return error.response.data?.errors?.full_messages.includes("is empty")
? { message: `name:${key}`, shouldFocus: true }
: { message: "name:server:generic", shouldFocus: true }
}
return { message: "name:server:generic", shouldFocus: true }
}
}
and then in account-settings.tsx
if (error.response?.data?.errors?.firstName) {
setError("firstName", handleNameServerErrors("firstName", error))
} else if (error.response?.data?.errors?.lastName) {
setError("lastName", handleNameServerErrors("lastName", error))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tallulahkay Thank you for that suggestion! I pushed an update to the handleNameServerErrors function. I pretty much used your solution but I kept setError within the function
@@ -96,7 +109,27 @@ const CreateAccountFooter = () => { | |||
) | |||
} | |||
|
|||
const onSubmit = (data) => { | |||
const handleCreateAccountErrors = | |||
(setError: (name: string, error: ErrorOption) => void) => (error: ExpandedAccountAxiosError) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making those updates! Works well
c37ec89
to
d77089c
Compare
d77089c
to
d313740
Compare
01eb138
to
59dd51b
Compare
59dd51b
to
6e73e1f
Compare
Description
This change introduces error handling to the Create Account page and also improves how we handle errors across the create account and account settings pages.
Jira ticket
DAH-2565
Checklist before requesting review
Version Control
angular
if it contains updates to Angular codetype: TICKET-NUMBER Description
format, e.g.feat: DAH-123 New Feature
Code quality
Review instructions
Request review
needs review
labelHousing Eng
group to automatically assign reviewers, and/or assign specific engineers