diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-22 01:23:19 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-22 01:23:19 +0800 |
commit | 35b505114842b8c8eac838fff8588adf17f54b45 (patch) | |
tree | 22b6840453818168d39352d439a110b5b28d4796 /packages/instant/src | |
parent | 094aabfcee8828eb5c5ba452edda306ef04757ce (diff) | |
download | dexon-sol-tools-35b505114842b8c8eac838fff8588adf17f54b45.tar dexon-sol-tools-35b505114842b8c8eac838fff8588adf17f54b45.tar.gz dexon-sol-tools-35b505114842b8c8eac838fff8588adf17f54b45.tar.bz2 dexon-sol-tools-35b505114842b8c8eac838fff8588adf17f54b45.tar.lz dexon-sol-tools-35b505114842b8c8eac838fff8588adf17f54b45.tar.xz dexon-sol-tools-35b505114842b8c8eac838fff8588adf17f54b45.tar.zst dexon-sol-tools-35b505114842b8c8eac838fff8588adf17f54b45.zip |
Always report unexpected errors. Move error message generation into helper function, and add tests
Diffstat (limited to 'packages/instant/src')
-rw-r--r-- | packages/instant/src/util/asset.ts | 17 | ||||
-rw-r--r-- | packages/instant/src/util/buy_quote_updater.ts | 29 |
2 files changed, 25 insertions, 21 deletions
diff --git a/packages/instant/src/util/asset.ts b/packages/instant/src/util/asset.ts index 40560d3eb..08f3642e3 100644 --- a/packages/instant/src/util/asset.ts +++ b/packages/instant/src/util/asset.ts @@ -1,3 +1,4 @@ +import { AssetBuyerError } from '@0x/asset-buyer'; import { AssetProxyId, ObjectMap } from '@0x/types'; import * as _ from 'lodash'; @@ -106,4 +107,20 @@ export const assetUtils = { ); return _.compact(erc20sOrUndefined); }, + assetBuyerErrorMessage: (asset: ERC20Asset, error: Error): string | undefined => { + if (error.message === AssetBuyerError.InsufficientAssetLiquidity) { + const assetName = assetUtils.bestNameForAsset(asset, 'of this asset'); + return `Not enough ${assetName} available`; + } else if (error.message === AssetBuyerError.InsufficientZrxLiquidity) { + return 'Not enough ZRX available'; + } else if ( + error.message === AssetBuyerError.StandardRelayerApiError || + error.message.startsWith(AssetBuyerError.AssetUnavailable) + ) { + const assetName = assetUtils.bestNameForAsset(asset, 'This asset'); + return `${assetName} is currently unavailable`; + } + + return undefined; + }, }; diff --git a/packages/instant/src/util/buy_quote_updater.ts b/packages/instant/src/util/buy_quote_updater.ts index 6cb5e41b6..4f97622e1 100644 --- a/packages/instant/src/util/buy_quote_updater.ts +++ b/packages/instant/src/util/buy_quote_updater.ts @@ -30,30 +30,17 @@ export const buyQuoteUpdater = { try { newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue, { feePercentage }); } catch (error) { - if (options.dispatchErrors) { - dispatch(actions.setQuoteRequestStateFailure()); - let errorMessage; - if (error.message === AssetBuyerError.InsufficientAssetLiquidity) { - const assetName = assetUtils.bestNameForAsset(asset, 'of this asset'); - errorMessage = `Not enough ${assetName} available`; - } else if (error.message === AssetBuyerError.InsufficientZrxLiquidity) { - errorMessage = 'Not enough ZRX available'; - } else if ( - error.message === AssetBuyerError.StandardRelayerApiError || - error.message.startsWith(AssetBuyerError.AssetUnavailable) - ) { - const assetName = assetUtils.bestNameForAsset(asset, 'This asset'); - errorMessage = `${assetName} is currently unavailable`; - } - if (!_.isUndefined(errorMessage)) { - errorFlasher.flashNewErrorMessage(dispatch, errorMessage); - } else { - throw error; - } - } else { + const errorMessage = assetUtils.assetBuyerErrorMessage(asset, error); + + if (_.isUndefined(errorMessage)) { + // This is an unknown error, report it to rollbar errorReporter.report(error); } + if (options.dispatchErrors) { + dispatch(actions.setQuoteRequestStateFailure()); + errorFlasher.flashNewErrorMessage(dispatch, errorMessage || 'Error fetching price, please try again'); + } return; } // We have a successful new buy quote |