fix: add proper error handling to fetch calls
Description
- Added proper error handling to fetch calls in Feedback and NewsletterSubscribe components
- Replaced .then() chains with async/await + try/catch for cleaner and safer logic
- Ensures network failures are caught and correct error UI is shown
Summary by CodeRabbit
- Refactor
- Modernized form submission handling and error management across subscription/feedback flows to make submissions more reliable.
- Bug Fixes
- Improved handling of failed submissions and unexpected errors to reduce user-facing submission failures.
βοΈ Tip: You can customize this high-level summary in your review settings.
Deploy Preview for asyncapi-website ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | d013e5dffcc6432f1c164621a4614025b6253bc2 |
| Latest deploy log | https://app.netlify.com/projects/asyncapi-website/deploys/6933fcf74f8d850008a5ddcc |
| Deploy Preview | https://deploy-preview-4687--asyncapi-website.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
Walkthrough
Two React components switch from promise chains to async/await and add try/catch around fetch, checking response status and handling response.json() with explicit success/error state updates.
Changes
| Cohort / File(s) | Summary |
|---|---|
Async/await fetch refactor components/Feedback.tsx, components/NewsletterSubscribe.tsx |
Converted .then()/.catch() promise chains to async/await with try/catch. Await fetch and response.json(), check non-200 status to set error state, and set submitted/success state on 200 responses. No exported signatures changed. |
Estimated code review effort
π― 2 (Simple) | β±οΈ ~8 minutes
- Same refactor pattern applied to both files; low logic density.
- Review focus: correct awaiting of response.json(), preserved state updates, and appropriate error messages.
Possibly related issues
- asyncapi/website#4686 β Implements async/await and try/catch in the same handleSubmit functions to address missing fetch error handling.
Suggested labels
ready-to-merge
Suggested reviewers
- derberg
- sambhavgupta0705
- anshgoyalevil
- Mayaleeeee
- asyncapi-bot-eve
Poem
π° I hopped through code, turned chains to await,
Try caught the winds and made errors abate,
Responses now parsed in a tidy queue,
A cleaner run β a carrot-chewed review!
Pre-merge checks and finishing touches
β Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title accurately describes the main change: converting fetch calls from promise chains to async/await with try/catch for improved error handling in two components. |
| Docstring Coverage | β Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
β¨ Finishing touches
- [ ] π Generate docstrings
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
β‘οΈ Lighthouse report for the changes in this PR:
| Category | Score |
|---|---|
| π΄ Performance | 40 |
| π’ Accessibility | 98 |
| π’ Best practices | 92 |
| π’ SEO | 100 |
| π΄ PWA | 33 |
Lighthouse ran on https://deploy-preview-4687--asyncapi-website.netlify.app/
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 100.00%. Comparing base (a677dc6) to head (d013e5d).
:warning: Report is 4 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #4687 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 799 799
Branches 146 146
=========================================
Hits 799 799
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.