Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Add try-catch blocks to artist dashboard sagas (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Shanks authored Oct 4, 2022
1 parent 907f45c commit fa2c9e8
Showing 1 changed file with 60 additions and 47 deletions.
107 changes: 60 additions & 47 deletions packages/web/src/pages/artist-dashboard-page/store/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@ function* fetchDashboardTracksAsync(action) {
const account = yield call(waitForValue, getAccountUser)
const { offset, limit } = action

const tracks = yield call(retrieveUserTracks, {
handle: account.handle,
currentUserId: account.user_id,
offset,
limit,
getUnlisted: true
})
const listedTracks = tracks.filter((t) => t.is_unlisted === false)
const unlistedTracks = tracks.filter((t) => t.is_unlisted === true)
try {
const tracks = yield call(retrieveUserTracks, {
handle: account.handle,
currentUserId: account.user_id,
offset,
limit,
getUnlisted: true
})
const listedTracks = tracks.filter((t) => t.is_unlisted === false)
const unlistedTracks = tracks.filter((t) => t.is_unlisted === true)

yield put(
dashboardActions.fetchDashboardTracksSucceeded(listedTracks, unlistedTracks)
)
yield put(
dashboardActions.fetchDashboardTracksSucceeded(
listedTracks,
unlistedTracks
)
)
} catch (error) {
console.error(error)
yield put(dashboardActions.fetchDashboardTracksFailed())
}
}

function* fetchDashboardAsync(action) {
Expand All @@ -44,43 +52,48 @@ function* fetchDashboardAsync(action) {
const account = yield call(waitForValue, getAccountUser)
const { offset, limit } = action

const [tracks, playlists] = yield all([
call(retrieveUserTracks, {
handle: account.handle,
currentUserId: account.user_id,
offset,
limit,
getUnlisted: true
}),
call(audiusBackendInstance.getPlaylists, account.user_id, [])
])
const listedTracks = tracks.filter((t) => t.is_unlisted === false)
const unlistedTracks = tracks.filter((t) => t.is_unlisted === true)

const trackIds = listedTracks.map((t) => t.track_id)
const now = moment()

yield call(fetchDashboardListenDataAsync, {
trackIds,
start: now.clone().subtract(1, 'years').toISOString(),
end: now.toISOString(),
period: 'month'
})
try {
const [tracks, playlists] = yield all([
call(retrieveUserTracks, {
handle: account.handle,
currentUserId: account.user_id,
offset,
limit,
getUnlisted: true
}),
call(audiusBackendInstance.getPlaylists, account.user_id, [])
])
const listedTracks = tracks.filter((t) => t.is_unlisted === false)
const unlistedTracks = tracks.filter((t) => t.is_unlisted === true)

const trackIds = listedTracks.map((t) => t.track_id)
const now = moment()

yield call(fetchDashboardListenDataAsync, {
trackIds,
start: now.clone().subtract(1, 'years').toISOString(),
end: now.toISOString(),
period: 'month'
})

if (
listedTracks.length > 0 ||
playlists.length > 0 ||
unlistedTracks.length > 0
) {
yield put(
dashboardActions.fetchDashboardSucceeded(
listedTracks,
playlists,
unlistedTracks
if (
listedTracks.length > 0 ||
playlists.length > 0 ||
unlistedTracks.length > 0
) {
yield put(
dashboardActions.fetchDashboardSucceeded(
listedTracks,
playlists,
unlistedTracks
)
)
)
yield call(pollForBalance)
} else {
yield call(pollForBalance)
} else {
yield put(dashboardActions.fetchDashboardFailed())
}
} catch (error) {
console.error(error)
yield put(dashboardActions.fetchDashboardFailed())
}
}
Expand Down

0 comments on commit fa2c9e8

Please sign in to comment.