From 6db06b331835abbf912811dd3d52d63b1563bcb0 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Tue, 6 Jun 2023 19:35:10 -0700 Subject: [PATCH] Add reason to account slice, handle fetch account failure with sentry (#3525) --- .../common/src/store/account/slice.ts | 6 +++++- .../web/src/common/store/account/sagas.js | 20 +++++++++++++++++-- .../packages/web/src/store/configureStore.ts | 3 ++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/audius-client/packages/common/src/store/account/slice.ts b/apps/audius-client/packages/common/src/store/account/slice.ts index 39d62117822..88e72f7ab89 100644 --- a/apps/audius-client/packages/common/src/store/account/slice.ts +++ b/apps/audius-client/packages/common/src/store/account/slice.ts @@ -13,7 +13,11 @@ import { TikTokAccountPayload, TwitterAccountPayload } from './types' -type FailureReason = 'ACCOUNT_DEACTIVATED' | 'ACCOUNT_NOT_FOUND' | 'LIBS_ERROR' +type FailureReason = + | 'ACCOUNT_DEACTIVATED' + | 'ACCOUNT_NOT_FOUND' + | 'ACCOUNT_NOT_FOUND_LOCAL' + | 'LIBS_ERROR' const initialState = { collections: {} as { [id: number]: AccountCollection }, diff --git a/apps/audius-client/packages/web/src/common/store/account/sagas.js b/apps/audius-client/packages/web/src/common/store/account/sagas.js index baf45abcc77..62c487414cd 100644 --- a/apps/audius-client/packages/web/src/common/store/account/sagas.js +++ b/apps/audius-client/packages/web/src/common/store/account/sagas.js @@ -9,13 +9,15 @@ import { createUserBankIfNeeded, getContext, FeatureFlags, - chatActions + chatActions, + ErrorLevel } from '@audius/common' import { call, put, fork, select, takeEvery } from 'redux-saga/effects' import { identify } from 'common/store/analytics/actions' import { addPlaylistsNotInLibrary } from 'common/store/playlist-library/sagas' import { updateProfileAsync } from 'common/store/profile/sagas' +import { reportToSentry } from 'store/errors/reportToSentry' import { waitForWrite, waitForRead } from 'utils/sagaHelpers' import { retrieveCollections } from '../cache/collections/utils' @@ -234,7 +236,7 @@ export function* fetchLocalAccountAsync() { cachedAccountUser.orderedPlaylists ) } else if (!currentUserExists) { - yield put(fetchAccountFailed({ reason: 'ACCOUNT_NOT_FOUND' })) + yield put(fetchAccountFailed({ reason: 'ACCOUNT_NOT_FOUND_LOCAL' })) } } @@ -383,6 +385,19 @@ function* watchFetchAccount() { yield takeEvery(fetchAccount.type, fetchAccountAsync) } +function* watchFetchAccountFailed() { + yield takeEvery(accountActions.fetchAccountFailed.type, function* (action) { + const userId = yield select(getUserId) + if (userId) { + yield call(reportToSentry, { + level: ErrorLevel.Error, + error: new Error(`Fetch account failed: ${action.payload.reason}`), + additionalInfo: { userId } + }) + } + }) +} + function* watchFetchLocalAccount() { yield takeEvery(fetchLocalAccount.type, fetchLocalAccountAsync) } @@ -415,6 +430,7 @@ export default function sagas() { return [ watchFetchAccount, watchFetchLocalAccount, + watchFetchAccountFailed, watchSignedIn, watchTwitterLogin, watchInstagramLogin, diff --git a/apps/audius-client/packages/web/src/store/configureStore.ts b/apps/audius-client/packages/web/src/store/configureStore.ts index 4471db1bdbe..50c5ff9043f 100644 --- a/apps/audius-client/packages/web/src/store/configureStore.ts +++ b/apps/audius-client/packages/web/src/store/configureStore.ts @@ -58,7 +58,8 @@ const statePruner = (state: AppState) => { return { account: { status: state.account.status, - userId: state.account.userId + userId: state.account.userId, + reason: state.account.reason }, pages: { profile: {