Skip to content

Fix: Improve Reliability of Currency Exchange Rate Fetching - #227

Merged
khanirfan18 merged 1 commit into
khanirfan18:mainfrom
TanCodeX:fix/hardcoded-currency-api-error-handling
Jul 9, 2026
Merged

Fix: Improve Reliability of Currency Exchange Rate Fetching#227
khanirfan18 merged 1 commit into
khanirfan18:mainfrom
TanCodeX:fix/hardcoded-currency-api-error-handling

Conversation

@TanCodeX

Copy link
Copy Markdown
Contributor

Summary

Closes #226

This PR improves the robustness of the currency exchange rate fetching logic in src/context/AppContext.jsx.

Previously, the app fetched data from the external API without validating the HTTP response or ensuring the returned payload was valid. This could lead to silent failures or incorrect exchange rate data being used in the application.


Changes Made

  • Added explicit check for res.ok before processing response
  • Validated API response structure to ensure returned JSON is correct
  • Added handling for known API error payloads (e.g., rate limit or invalid response formats)
  • Introduced descriptive error throwing when validation fails
  • Wrapped fetch logic in proper error handling to catch and manage failures gracefully

Why This Matters

  • Prevents silent failures in currency conversion logic

  • Ensures only valid exchange rate data is used in the app

  • Improves resilience against:

    • API downtime
    • Rate limiting
    • Malformed responses
  • Makes debugging easier with clear error messages


Behavior Change

  • Before: Invalid API response → silent failure or incorrect data ❌
  • Now: Invalid API response → caught and handled gracefully with error logging ✅

Testing

  • Simulate API downtime → app should not crash
  • Simulate rate limit response → error should be caught and handled
  • Valid response → exchange rates load correctly
  • Invalid JSON structure → fallback/error handling triggered

Impact

  • Improved data reliability for currency conversion
  • Better error visibility for debugging
  • Enhanced stability for financial features

@netlify

netlify Bot commented Jun 21, 2026

Copy link
Copy Markdown

👷 Deploy request for finnboard0 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 27554f7

@netlify

netlify Bot commented Jun 21, 2026

Copy link
Copy Markdown

Deploy Preview for finnboard ready!

Name Link
🔨 Latest commit 27554f7
🔍 Latest deploy log https://app.netlify.com/projects/finnboard/deploys/6a37cda9c2b33c0008d24b47
😎 Deploy Preview https://deploy-preview-227--finnboard.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.

@TanCodeX

Copy link
Copy Markdown
Contributor Author

@khanirfan18 Please review!!

@TanCodeX

TanCodeX commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

@khanirfan18 review!

@khanirfan18
khanirfan18 merged commit f0d6c94 into khanirfan18:main Jul 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Hardcoded Currency API Without Proper Error Handling

2 participants