Skip to content

Commit

Permalink
Fix sentry errors (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Slipchenko authored Apr 13, 2022
1 parent 307a530 commit 64363d3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/accounts/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import { LedgerSignRequest } from 'ledger/types';
import { ledgerService } from 'ledger/service';
import { initUiSentry } from 'sentry';

initUiSentry('accounts');
initUiSentry({
ignoreErrorContext: 'beforeSendAccounts',
source: 'accounts',
});

log.setDefaultLevel(KEEPERWALLET_DEBUG ? 'debug' : 'warn');

Expand Down
8 changes: 7 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Sentry.init({
const backgroundService = await bgPromise;

const shouldIgnore =
backgroundService.remoteConfigController.shouldIgnoreError(
'beforeSend',
message
) ||
backgroundService.remoteConfigController.shouldIgnoreError(
'beforeSendBackground',
message
Expand Down Expand Up @@ -1117,7 +1121,9 @@ class BackgroundService extends EventEmitter {
account,
network: this._getCurrentNetwork(state.selectedAccount),
messages,
txVersion: getTxVersions(state.selectedAccount.type),
txVersion: getTxVersions(
state.selectedAccount ? state.selectedAccount.type : 'seed'
),
};
}

Expand Down
12 changes: 10 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,16 @@ export const IGNORE_ERRORS_CONFIG_UPDATE_INTERVAL = 60000;

export const DEFAULT_IGNORE_ERRORS_CONFIG = {
ignoreAll: false,
beforeSendBackground: ['Failed to fetch'],
beforeSendPopup: ['Failed to fetch'],
beforeSend: [
'An operation that changes interface state is in progress',
'Failed to fetch',
'NetworkError when attempting to fetch resource',
'No device selected',
'The operation was aborted',
],
beforeSendAccounts: [],
beforeSendBackground: [],
beforeSendPopup: [],
contentScriptApprove: [] as string[],
popupApprove: [] as string[],
};
Expand Down
4 changes: 0 additions & 4 deletions src/controllers/AssetInfoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ export class AssetInfoController {
if (resp.ok) {
this.suspiciousAssets = (await resp.text()).split('\n').sort();
this.suspiciousLastUpdated = new Date().getTime();
} else {
if (resp.status < 500 && resp.status !== 403) {
throw new Error(await resp.text());
}
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/sentry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { KEEPERWALLET_DEBUG } from '../constants';
import * as Sentry from '@sentry/react';
import backgroundService from 'ui/services/Background';

export function initUiSentry(source: 'popup' | 'accounts') {
export function initUiSentry({
ignoreErrorContext,
source,
}: {
ignoreErrorContext: 'beforeSendAccounts' | 'beforeSendPopup';
source: 'popup' | 'accounts';
}) {
return Sentry.init({
dsn: __SENTRY_DSN__,
environment: __SENTRY_ENVIRONMENT__,
Expand All @@ -25,10 +31,12 @@ export function initUiSentry(source: 'popup' | 'accounts') {
? hint.originalException.message
: String(hint.originalException);

const shouldIgnore = await backgroundService.shouldIgnoreError(
'beforeSendPopup',
message
);
const [shouldIgnoreGlobal, shouldIgnoreContext] = await Promise.all([
backgroundService.shouldIgnoreError('beforeSend', message),
backgroundService.shouldIgnoreError(ignoreErrorContext, message),
]);

const shouldIgnore = shouldIgnoreGlobal || shouldIgnoreContext;

if (shouldIgnore) {
return null;
Expand Down
5 changes: 4 additions & 1 deletion src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import { initUiSentry } from 'sentry';

const isNotificationWindow = window.location.pathname === '/notification.html';

initUiSentry('popup');
initUiSentry({
ignoreErrorContext: 'beforeSendPopup',
source: 'popup',
});

log.setDefaultLevel(KEEPERWALLET_DEBUG ? 'debug' : 'warn');

Expand Down
7 changes: 3 additions & 4 deletions src/ui/components/pages/BackupSeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import * as React from 'react';
import { Trans } from 'react-i18next';
import { Button, Copy, Modal } from '../ui';
import { PAGES } from '../../pageConfig';
import { useAccountsSelector, useAppDispatch } from 'accounts/store';
import { useAccountsSelector } from 'accounts/store';

export function BackUpSeed({ setTab }) {
const dispatch = useAppDispatch();
const [showCopy, setShowCopy] = React.useState<boolean>(false);
const newAccount = useAccountsSelector(state => state.localState.newAccount);

Expand Down Expand Up @@ -47,12 +46,12 @@ export function BackUpSeed({ setTab }) {
id="continue"
className="margin-main-big"
type="submit"
onClick={() => dispatch(setTab(PAGES.CONFIRM_BACKUP))}
onClick={() => setTab(PAGES.CONFIRM_BACKUP)}
>
<Trans i18nKey="backupSeed.continue">Continue</Trans>
</Button>

<Button id="cancelCreation" onClick={() => dispatch(setTab(PAGES.ROOT))}>
<Button id="cancelCreation" onClick={() => setTab(PAGES.ROOT)}>
<Trans i18nKey="backupSeed.cancel">Cancel creation</Trans>
</Button>

Expand Down
6 changes: 6 additions & 0 deletions src/ui/components/pages/swap/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ export function Swap({ setTab }: Props) {
}
return;
}

if (/Request is rejected on ledger/i.test(errMessage)) {
setSwapErrorMessage(errMessage);
setIsSwapInProgress(false);
return;
}
}

setSwapErrorMessage(errMessage || t('swap.failMessage'));
Expand Down

0 comments on commit 64363d3

Please sign in to comment.