Fix error handling

This commit is contained in:
IshaVenikar 2024-07-15 17:07:29 +05:30 committed by Adw8
parent 26df4ba42f
commit 3e5135aa03

View File

@ -55,18 +55,23 @@ const SignWithCosmos = () => {
}), }),
}); });
if (response.status === 429) { if (response.ok) {
const errorResponse = await response.json(); enqueueSnackbar('Tokens sent successfully', { variant: "success" });
enqueueSnackbar(`${response.statusText} : ${errorResponse.error}`, { variant: "error" }); } else {
setIsRequesting(false); if (response.status === 429) {
throw new Error('Failed to send request'); const errorResponse = await response.json();
enqueueSnackbar(`${response.statusText} : ${errorResponse.error}`, { variant: "error" });
setIsRequesting(false);
} else {
throw new Error('Failed to send request');
}
} }
getBalances(); getBalances();
setIsRequesting(false); setIsRequesting(false);
enqueueSnackbar('Tokens sent successfully', { variant: "success" });
} catch (error) { } catch (error) {
console.error('Error:', error); console.error('Error:', error);
throw error;
} }
}; };