From 76d4e033018d9a34fb32e0ea0b1b99d375b05a2b Mon Sep 17 00:00:00 2001 From: harshitsharma2005 Date: Mon, 13 Oct 2025 19:50:45 +0530 Subject: [PATCH] Add retry button to ErrorMessage component for weather data fetching - Enhanced ErrorMessage component to accept optional onRetry prop - Added styled retry button that appears when onRetry function is provided - Improved error styling with better visual hierarchy - Weather component now supports manual retry for failed API calls - Maintains backward compatibility with existing ErrorMessage usage Fixes: Add retry button for weather data API/network errors --- src/components/ErrorMessage.jsx | 33 ++++++++++++++++++++++++++++++--- src/styles.css | 18 +++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/components/ErrorMessage.jsx b/src/components/ErrorMessage.jsx index 0b14dd8..147336c 100644 --- a/src/components/ErrorMessage.jsx +++ b/src/components/ErrorMessage.jsx @@ -1,4 +1,31 @@ -export default function ErrorMessage({ error }) { - if (!error) return null; - return
Error: {error.toString()}
; +export default function ErrorMessage({ error, message, onRetry }) { + if (!error && !message) return null; + + const displayMessage = message || error?.toString() || 'An error occurred'; + + return ( +
+
+ ❌ {displayMessage} +
+ {onRetry && ( + + )} +
+ ); } diff --git a/src/styles.css b/src/styles.css index d837b58..2ab98fd 100644 --- a/src/styles.css +++ b/src/styles.css @@ -56,7 +56,23 @@ input, select { background:var(--bg-alt); } /* Status */ .loading { padding:0.5rem 0; opacity:0.8; } -.error { color:var(--danger); font-weight:600; } +.error { + color:var(--danger); + font-weight:600; + padding: 1rem; + background: var(--bg-alt); + border: 1px solid var(--danger); + border-radius: var(--radius); + margin: 1rem 0; + text-align: center; +} +.error-message { + margin-bottom: 0.5rem; +} +.retry-button:hover { + background: #005a9e !important; + transform: translateY(-1px); +} .correct { background: #16a34a !important; color:#fff; } .wrong { background:#dc2626 !important; color:#fff; }