diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-07-13 06:50:13 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-07-13 06:56:01 +0800 |
commit | ac5588c7c436e2540f87e432446e103d35c9221a (patch) | |
tree | 75fb70ebf9cfb0aaa3450610f2072a43c3b2f1bc /packages | |
parent | ddb70a89ad99527e03844d23e7c0f3522e98a602 (diff) | |
download | dexon-sol-tools-ac5588c7c436e2540f87e432446e103d35c9221a.tar dexon-sol-tools-ac5588c7c436e2540f87e432446e103d35c9221a.tar.gz dexon-sol-tools-ac5588c7c436e2540f87e432446e103d35c9221a.tar.bz2 dexon-sol-tools-ac5588c7c436e2540f87e432446e103d35c9221a.tar.lz dexon-sol-tools-ac5588c7c436e2540f87e432446e103d35c9221a.tar.xz dexon-sol-tools-ac5588c7c436e2540f87e432446e103d35c9221a.tar.zst dexon-sol-tools-ac5588c7c436e2540f87e432446e103d35c9221a.zip |
Make error reporter not return a promise and add more environment possibilities
Diffstat (limited to 'packages')
-rw-r--r-- | packages/website/ts/blockchain.ts | 6 | ||||
-rw-r--r-- | packages/website/ts/components/eth_weth_conversion_button.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/components/fill_order.tsx | 4 | ||||
-rw-r--r-- | packages/website/ts/components/generate_order/generate_order_form.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/components/inputs/allowance_toggle.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/components/order_json.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/components/send_button.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/components/token_balances.tsx | 4 | ||||
-rw-r--r-- | packages/website/ts/components/wallet/wrap_ether_item.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/types.ts | 2 | ||||
-rw-r--r-- | packages/website/ts/utils/configs.ts | 5 | ||||
-rw-r--r-- | packages/website/ts/utils/error_reporter.ts | 22 | ||||
-rw-r--r-- | packages/website/ts/utils/fetch_utils.ts | 3 | ||||
-rw-r--r-- | packages/website/ts/utils/utils.ts | 36 |
14 files changed, 51 insertions, 43 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 0e6698318..868ffad03 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -571,7 +571,7 @@ export class Blockchain { configs.DEFAULT_TRACKED_TOKEN_SYMBOLS, )}) not found in tokenRegistry: ${JSON.stringify(tokenRegistryTokens)}`, ); - await errorReporter.reportAsync(err); + errorReporter.report(err); return; } if (_.isEmpty(trackedTokensByAddress)) { @@ -683,7 +683,7 @@ export class Blockchain { // errors will be thrown by `watch`. For now, let's log the error // to rollbar and stop watching when one occurs // tslint:disable-next-line:no-floating-promises - errorReporter.reportAsync(err); // fire and forget + errorReporter.report(err); // fire and forget return; } else { const decodedLog = decodedLogEvent.log; @@ -915,7 +915,7 @@ export class Blockchain { if (_.includes(errMsg, 'not been deployed to detected network')) { throw new Error(BlockchainCallErrs.ContractDoesNotExist); } else { - await errorReporter.reportAsync(err); + errorReporter.report(err); throw new Error(BlockchainCallErrs.UnhandledError); } } diff --git a/packages/website/ts/components/eth_weth_conversion_button.tsx b/packages/website/ts/components/eth_weth_conversion_button.tsx index 4b91a2ebd..d547a4e6a 100644 --- a/packages/website/ts/components/eth_weth_conversion_button.tsx +++ b/packages/website/ts/components/eth_weth_conversion_button.tsx @@ -118,7 +118,7 @@ export class EthWethConversionButton extends React.Component< ? 'Failed to wrap your ETH. Please try again.' : 'Failed to unwrap your WETH. Please try again.'; this.props.dispatcher.showFlashMessage(errorMsg); - await errorReporter.reportAsync(err); + errorReporter.report(err); } } this.setState({ diff --git a/packages/website/ts/components/fill_order.tsx b/packages/website/ts/components/fill_order.tsx index 03ba1183d..9360ba24c 100644 --- a/packages/website/ts/components/fill_order.tsx +++ b/packages/website/ts/components/fill_order.tsx @@ -583,7 +583,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> { this.setState({ globalErrMsg, }); - await errorReporter.reportAsync(err); + errorReporter.report(err); return; } } @@ -654,7 +654,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> { this.setState({ globalErrMsg, }); - await errorReporter.reportAsync(err); + errorReporter.report(err); return; } } diff --git a/packages/website/ts/components/generate_order/generate_order_form.tsx b/packages/website/ts/components/generate_order/generate_order_form.tsx index d26b5c3fa..7d7df5506 100644 --- a/packages/website/ts/components/generate_order/generate_order_form.tsx +++ b/packages/website/ts/components/generate_order/generate_order_form.tsx @@ -349,7 +349,7 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G globalErrMsg = 'An unexpected error occured. Please try refreshing the page'; logUtils.log(`Unexpected error occured: ${err}`); logUtils.log(err.stack); - await errorReporter.reportAsync(err); + errorReporter.report(err); } } this.setState({ diff --git a/packages/website/ts/components/inputs/allowance_toggle.tsx b/packages/website/ts/components/inputs/allowance_toggle.tsx index 0d5995696..ff3a01136 100644 --- a/packages/website/ts/components/inputs/allowance_toggle.tsx +++ b/packages/website/ts/components/inputs/allowance_toggle.tsx @@ -129,7 +129,7 @@ export class AllowanceToggle extends React.Component<AllowanceToggleProps, Allow logUtils.log(`Unexpected error encountered: ${err}`); logUtils.log(err.stack); this.props.onErrorOccurred(BalanceErrs.allowanceSettingFailed); - await errorReporter.reportAsync(err); + errorReporter.report(err); } } private _isAllowanceSet(): boolean { diff --git a/packages/website/ts/components/order_json.tsx b/packages/website/ts/components/order_json.tsx index 35188c024..965bd5455 100644 --- a/packages/website/ts/components/order_json.tsx +++ b/packages/website/ts/components/order_json.tsx @@ -154,7 +154,7 @@ You can see and fill it here: ${this.state.shareLink}`); if (response.status !== 200 || bodyObj.status_code !== 200) { // TODO: Show error message in UI logUtils.log(`Unexpected status code: ${response.status} -> ${responseBody}`); - await errorReporter.reportAsync(new Error(`Bitly returned non-200: ${JSON.stringify(response)}`)); + errorReporter.report(new Error(`Bitly returned non-200: ${JSON.stringify(response)}`)); return ''; } return bodyObj.data.url; diff --git a/packages/website/ts/components/send_button.tsx b/packages/website/ts/components/send_button.tsx index 8486dbd8b..ac55d430b 100644 --- a/packages/website/ts/components/send_button.tsx +++ b/packages/website/ts/components/send_button.tsx @@ -80,7 +80,7 @@ export class SendButton extends React.Component<SendButtonProps, SendButtonState logUtils.log(`Unexpected error encountered: ${err}`); logUtils.log(err.stack); this.props.onError(); - await errorReporter.reportAsync(err); + errorReporter.report(err); } } this.setState({ diff --git a/packages/website/ts/components/token_balances.tsx b/packages/website/ts/components/token_balances.tsx index 3fae83c00..c9b313736 100644 --- a/packages/website/ts/components/token_balances.tsx +++ b/packages/website/ts/components/token_balances.tsx @@ -526,7 +526,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala this.setState({ errorType: BalanceErrs.mintingFailed, }); - await errorReporter.reportAsync(err); + errorReporter.report(err); return false; } } @@ -561,7 +561,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala this.setState({ errorType, }); - await errorReporter.reportAsync(new Error(`Faucet returned non-200: ${JSON.stringify(response)}`)); + errorReporter.report(new Error(`Faucet returned non-200: ${JSON.stringify(response)}`)); return false; } diff --git a/packages/website/ts/components/wallet/wrap_ether_item.tsx b/packages/website/ts/components/wallet/wrap_ether_item.tsx index 2b4cf93fe..76b349c0b 100644 --- a/packages/website/ts/components/wallet/wrap_ether_item.tsx +++ b/packages/website/ts/components/wallet/wrap_ether_item.tsx @@ -219,7 +219,7 @@ export class WrapEtherItem extends React.Component<WrapEtherItemProps, WrapEther this.props.dispatcher.showFlashMessage('Failed to unwrap your WETH. Please try again.'); analytics.logEvent('Portal', 'Unwrap WETH Failed', networkName); } - await errorReporter.reportAsync(err); + errorReporter.report(err); } } this.setState({ diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts index e8dc694f6..c2a0f9640 100644 --- a/packages/website/ts/types.ts +++ b/packages/website/ts/types.ts @@ -244,6 +244,8 @@ export enum BlockchainCallErrs { export enum Environments { DEVELOPMENT = 'DEVELOPMENT', + DOGFOOD = 'DOGFOOD', + STAGING = 'STAGING', PRODUCTION = 'PRODUCTION', } diff --git a/packages/website/ts/utils/configs.ts b/packages/website/ts/utils/configs.ts index 97aabd13d..745328d0a 100644 --- a/packages/website/ts/utils/configs.ts +++ b/packages/website/ts/utils/configs.ts @@ -2,10 +2,6 @@ import * as _ from 'lodash'; import { Environments, OutdatedWrappedEtherByNetworkId, PublicNodeUrlsByNetworkId } from 'ts/types'; const BASE_URL = window.location.origin; -const isDevelopment = _.includes( - ['https://0xproject.localhost:3572', 'https://localhost:3572', 'https://127.0.0.1'], - BASE_URL, -); const INFURA_API_KEY = 'T5WSC8cautR4KXyYgsRs'; export const configs = { @@ -21,7 +17,6 @@ export const configs = { DOMAIN_DOGFOOD: 'dogfood.0xproject.com', DOMAIN_DEVELOPMENT: '0xproject.localhost:3572', DOMAIN_PRODUCTION: '0xproject.com', - ENVIRONMENT: isDevelopment ? Environments.DEVELOPMENT : Environments.PRODUCTION, GOOGLE_ANALYTICS_ID: 'UA-98720122-1', LAST_LOCAL_STORAGE_FILL_CLEARANCE_DATE: '2017-11-22', LAST_LOCAL_STORAGE_TRACKED_TOKEN_CLEARANCE_DATE: '2018-7-5', diff --git a/packages/website/ts/utils/error_reporter.ts b/packages/website/ts/utils/error_reporter.ts index 2d0661b25..d38269d92 100644 --- a/packages/website/ts/utils/error_reporter.ts +++ b/packages/website/ts/utils/error_reporter.ts @@ -2,6 +2,7 @@ import { logUtils } from '@0xproject/utils'; import { Environments } from 'ts/types'; import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; +import { utils } from 'ts/utils/utils'; // Suggested way to include Rollbar with Webpack // https://github.com/rollbar/rollbar.js/tree/master/examples/webpack @@ -12,7 +13,7 @@ const rollbarConfig = { itemsPerMinute: 10, maxItems: 500, payload: { - environment: configs.ENVIRONMENT, + environment: utils.getEnvironment(), client: { javascript: { source_map_enabled: true, @@ -40,21 +41,14 @@ import Rollbar = require('../../public/js/rollbar.umd.min.js'); const rollbar = Rollbar.init(rollbarConfig); export const errorReporter = { - async reportAsync(err: Error): Promise<any> { - if (configs.ENVIRONMENT === Environments.DEVELOPMENT) { + report(err: Error): void { + if (utils.getEnvironment() === Environments.DEVELOPMENT) { return; // Let's not log development errors to rollbar } - - return new Promise((resolve, _reject) => { - rollbar.error(err, (rollbarErr: Error) => { - if (rollbarErr) { - logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`); - // We never want to reject and cause the app to throw because of rollbar - resolve(); - } else { - resolve(); - } - }); + rollbar.error(err, (rollbarErr: Error) => { + if (rollbarErr) { + logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`); + } }); }, }; diff --git a/packages/website/ts/utils/fetch_utils.ts b/packages/website/ts/utils/fetch_utils.ts index 513f7e479..a56d89262 100644 --- a/packages/website/ts/utils/fetch_utils.ts +++ b/packages/website/ts/utils/fetch_utils.ts @@ -9,8 +9,7 @@ const logErrorIfPresent = (response: Response, requestedURL: string) => { const errorText = `Error requesting url: ${requestedURL}, ${response.status}: ${response.statusText}`; logUtils.log(errorText); const error = Error(errorText); - // tslint:disable-next-line:no-floating-promises - errorReporter.reportAsync(error); + errorReporter.report(error); throw error; } }; diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 1d669d8f0..240170113 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -31,8 +31,6 @@ import { constants } from 'ts/utils/constants'; import { errorReporter } from 'ts/utils/error_reporter'; import * as u2f from 'ts/vendor/u2f_api'; -const isDogfood = (): boolean => _.includes(window.location.href, configs.DOMAIN_DOGFOOD); - export const utils = { assert(condition: boolean, message: string): void { if (!condition) { @@ -347,10 +345,13 @@ export const utils = { return parsedProviderName; }, getBackendBaseUrl(): string { - return isDogfood() ? configs.BACKEND_BASE_STAGING_URL : configs.BACKEND_BASE_PROD_URL; + return utils.isDogfood() ? configs.BACKEND_BASE_STAGING_URL : configs.BACKEND_BASE_PROD_URL; }, isDevelopment(): boolean { - return configs.ENVIRONMENT === Environments.DEVELOPMENT; + return _.includes( + ['https://0xproject.localhost:3572', 'https://localhost:3572', 'https://127.0.0.1'], + window.location.origin, + ); }, isStaging(): boolean { return _.includes(window.location.href, configs.DOMAIN_STAGING); @@ -358,7 +359,27 @@ export const utils = { isExternallyInjected(providerType: ProviderType, injectedProviderName: string): boolean { return providerType === ProviderType.Injected && injectedProviderName !== constants.PROVIDER_NAME_PUBLIC; }, - isDogfood, + isDogfood(): boolean { + return _.includes(window.location.href, configs.DOMAIN_DOGFOOD); + }, + isProduction(): boolean { + return _.includes(window.location.href, configs.DOMAIN_PRODUCTION); + }, + getEnvironment(): Environments { + if (utils.isDogfood()) { + return Environments.DOGFOOD; + } + if (utils.isDevelopment()) { + return Environments.DEVELOPMENT; + } + if (utils.isStaging()) { + return Environments.STAGING; + } + if (utils.isProduction()) { + return Environments.PRODUCTION; + } + return undefined; + }, shouldShowJobsPage(): boolean { return this.isDevelopment() || this.isStaging() || this.isDogfood(); }, @@ -391,10 +412,7 @@ export const utils = { const format = `0,0.${_.repeat('0', precision)}`; const formattedAmount = numeral(unitAmount).format(format); if (_.isNaN(formattedAmount)) { - // tslint:disable-next-line:no-floating-promises - errorReporter.reportAsync( - new Error(`amount ${BigNumber}, decimals ${decimals} could not be formatted and returned NaN.`), - ); + // https://github.com/adamwdraper/Numeral-js/issues/596 return format; } return formattedAmount; |