Feat: Add SubscriptionList#80
Conversation
| const emailEncoded = encodeURIComponent(email) | ||
| const url = baseURL + emailEncoded + urlEnd | ||
|
|
||
| fetch(url, { method: 'POST' }) |
There was a problem hiding this comment.
I think we should improve error handling.
For fetch(), 4xx and 5xx responses are not errors. They represent an error on the part of the API, but they don't trigger the .catch() (98). This means that if there is any error in zapier, or one of the services it uses, and fetch() returns 500, the user will get a success message, when in fact the email won't be registered to the subscription list.
There was a problem hiding this comment.
That makes sense, @PedroAntunesCosta. I updated the Zapier fetch flow to use async/await and to show the success message only when response.ok is true. If the API returns a 4xx or 5xx status code, the user now sees the generic error message (subscription_list.error) instead of the success message.
The change is in this commit. Let me know what you think of this change.
| return | ||
| } | ||
|
|
||
| const isValid = await checkEmail(email) |
There was a problem hiding this comment.
The error treatment here is innacurate. checkEmail(email) can return false for reasons other than invalid emails:
- The RapidAPI request fails.
- The RapidAPI response is otherwise unusable.
- NEXT_PUBLIC_NEWSLETTER_API_KEY is missing - (E.g., I tested the component with storybook and entered my VTEX email. I got the 'invalid email' error message and this was probably the reason.) This is probably not an issue in production once the environment is correctly configured.
There was a problem hiding this comment.
Thanks again, Pedro! The checkEmail now returns 'valid' | 'invalid' | 'error' instead of a boolean:
invalid: shows the invalid email message (only when RapidAPI returns block: true).error:shows the generic error message (RapidAPI failure, unusable response, missing API key, etc.)
It also checksresponse.okbefore parsing the RapidAPI response.
To test in Storybook, NEXT_PUBLIC_NEWSLETTER_API_KEY needs to be set before running yarn storybook. Without it, the expected behavior is the generic error message: not “invalid email”.
I'll also follow up with Bruno to confirm that NEXT_PUBLIC_NEWSLETTER_API_KEY is configured on Netlify environments.
Co-authored-by: Cursor <cursoragent@cursor.com>
Distinguish invalid emails from API failures and check Zapier response.ok before showing success. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@PedroAntunesCosta só mais uma dúvida em relação à variável de ambiente. Não tenho acesso ao netlify.
|
Description
To test locally:
yarn install.feat/subscription-list:git checkout feat/subscription-list.yarn storybook.http://localhost:6006/and navigate to SubscriptionList in the left sidebar.Types of changes