Handle error using snackbar

This commit is contained in:
Adw8 2024-07-17 16:23:46 +05:30
parent f7c88e883f
commit 920190d367

View File

@ -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);
}
};