Skip to content

Commit

Permalink
Add reason to account slice, handle fetch account failure with sentry (
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed Jun 7, 2023
1 parent 67ee0c0 commit 6db06b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
20 changes: 18 additions & 2 deletions apps/audius-client/packages/web/src/common/store/account/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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' }))
}
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -415,6 +430,7 @@ export default function sagas() {
return [
watchFetchAccount,
watchFetchLocalAccount,
watchFetchAccountFailed,
watchSignedIn,
watchTwitterLogin,
watchInstagramLogin,
Expand Down
3 changes: 2 additions & 1 deletion apps/audius-client/packages/web/src/store/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 6db06b3

Please sign in to comment.