From 920190d367ec79214154d4db95c2f5b4ba492ca6 Mon Sep 17 00:00:00 2001 From: Adw8 Date: Wed, 17 Jul 2024 16:23:46 +0530 Subject: [PATCH] Handle error using snackbar --- src/pages/SignWithCosmos.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/SignWithCosmos.tsx b/src/pages/SignWithCosmos.tsx index 6008eff..bb8f44b 100644 --- a/src/pages/SignWithCosmos.tsx +++ b/src/pages/SignWithCosmos.tsx @@ -54,24 +54,24 @@ const SignWithCosmos = () => { address: cosmosAddress, }), }); - + if (response.ok) { enqueueSnackbar('Tokens sent successfully', { variant: "success" }); } else { + const errorResponse = await response.json(); if (response.status === 429) { - const errorResponse = await response.json(); enqueueSnackbar(`${response.statusText} : ${errorResponse.error}`, { variant: "error" }); - setIsRequesting(false); } else { - throw new Error('Failed to send request'); + throw new Error(errorResponse.error); } } getBalances(); - setIsRequesting(false); } catch (error) { - console.error('Error:', error); - throw error; + console.error(error); + enqueueSnackbar("Error getting tokens from faucet", { variant: "error" }); + } finally { + setIsRequesting(false); } };