diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-11-02 04:49:09 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-11-02 04:49:09 +0800 |
commit | 9fd931f7991398b9a6331d7bc5b8cd7a41491be9 (patch) | |
tree | 6ecef620c98e5d667479ca0c2e7b709617453fc8 /packages | |
parent | 57fba86154451a247dc008a9080e1e65145e6778 (diff) | |
download | dexon-sol-tools-9fd931f7991398b9a6331d7bc5b8cd7a41491be9.tar dexon-sol-tools-9fd931f7991398b9a6331d7bc5b8cd7a41491be9.tar.gz dexon-sol-tools-9fd931f7991398b9a6331d7bc5b8cd7a41491be9.tar.bz2 dexon-sol-tools-9fd931f7991398b9a6331d7bc5b8cd7a41491be9.tar.lz dexon-sol-tools-9fd931f7991398b9a6331d7bc5b8cd7a41491be9.tar.xz dexon-sol-tools-9fd931f7991398b9a6331d7bc5b8cd7a41491be9.tar.zst dexon-sol-tools-9fd931f7991398b9a6331d7bc5b8cd7a41491be9.zip |
feat: better handle errors in async fetches
Diffstat (limited to 'packages')
-rw-r--r-- | packages/instant/src/redux/async_data.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index f8dbe9fd4..716558409 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -3,19 +3,20 @@ import * as _ from 'lodash'; import { BIG_NUMBER_ZERO } from '../constants'; import { assetUtils } from '../util/asset'; import { coinbaseApi } from '../util/coinbase_api'; +import { errorFlasher } from '../util/error_flasher'; import { actions } from './actions'; import { Store } from './store'; export const asyncData = { fetchEthPriceAndDispatchToStore: async (store: Store) => { - let ethUsdPrice = BIG_NUMBER_ZERO; try { - ethUsdPrice = await coinbaseApi.getEthUsdPrice(); - } catch (e) { - // ignore - } finally { + const ethUsdPrice = await coinbaseApi.getEthUsdPrice(); store.dispatch(actions.updateEthUsdPrice(ethUsdPrice)); + } catch (e) { + const errorMessage = 'Error fetching ETH/USD price'; + errorFlasher.flashNewErrorMessage(store.dispatch, errorMessage); + store.dispatch(actions.updateEthUsdPrice(BIG_NUMBER_ZERO)); } }, fetchAvailableAssetDatasAndDispatchToStore: async (store: Store) => { @@ -26,7 +27,10 @@ export const asyncData = { const assets = assetUtils.createAssetsFromAssetDatas(assetDatas, assetMetaDataMap, network); store.dispatch(actions.setAvailableAssets(assets)); } catch (e) { - // ignore + const errorMessage = 'Error fetching available assets'; + errorFlasher.flashNewErrorMessage(store.dispatch, errorMessage); + // On error, just specify that none are available + store.dispatch(actions.setAvailableAssets([])); } } }, |