website icon indicating copy to clipboard operation
website copied to clipboard

fix: add proper error handling to fetch calls

Open sarthakNITT opened this issue 1 month ago β€’ 4 comments

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.

sarthakNITT avatar Dec 06 '25 09:12 sarthakNITT

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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify[bot] avatar Dec 06 '25 09:12 netlify[bot]

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.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 06 '25 09:12 coderabbitai[bot]

⚑️ 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/

asyncapi-bot avatar Dec 06 '25 09:12 asyncapi-bot

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.

codecov[bot] avatar Dec 06 '25 09:12 codecov[bot]