mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
fix(api): continue crawling when access token refresh fails for one user
This commit is contained in:
parent
721f979cc8
commit
0c2188c4d4
1 changed files with 16 additions and 10 deletions
|
|
@ -50,14 +50,20 @@ export class SpotifyService {
|
||||||
playHistory = await this.spotifyApi.getRecentlyPlayedTracks(user.spotify);
|
playHistory = await this.spotifyApi.getRecentlyPlayedTracks(user.spotify);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.response && err.response.status === 401 && retryOnExpiredToken) {
|
if (err.response && err.response.status === 401 && retryOnExpiredToken) {
|
||||||
const accessToken = await this.spotifyAuth.refreshAccessToken(
|
try {
|
||||||
user.spotify
|
const accessToken = await this.spotifyAuth.refreshAccessToken(
|
||||||
);
|
user.spotify
|
||||||
await this.usersService.updateSpotifyConnection(user, {
|
);
|
||||||
...user.spotify,
|
await this.usersService.updateSpotifyConnection(user, {
|
||||||
accessToken,
|
...user.spotify,
|
||||||
});
|
accessToken,
|
||||||
await this.crawlListensForUser(user, false);
|
});
|
||||||
|
await this.crawlListensForUser(user, false);
|
||||||
|
} catch (errFromAuth) {
|
||||||
|
this.logger.error(
|
||||||
|
`Refreshing access token failed for user "${user.id}": ${errFromAuth}`
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO sent to sentry
|
// TODO sent to sentry
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
|
|
@ -65,7 +71,7 @@ export class SpotifyService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes no sense to keep processing the (inexistant) data but if we throw
|
// Makes no sense to keep processing the (inexistent) data but if we throw
|
||||||
// the error the fetch loop will not process other users.
|
// the error the fetch loop will not process other users.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +117,7 @@ export class SpotifyService {
|
||||||
* The variable will still be set, in case we want to add the functionality
|
* The variable will still be set, in case we want to add the functionality
|
||||||
* again.
|
* again.
|
||||||
*/
|
*/
|
||||||
this.usersService.updateSpotifyConnection(user, {
|
await this.usersService.updateSpotifyConnection(user, {
|
||||||
...user.spotify,
|
...user.spotify,
|
||||||
lastRefreshTime: newestPlayTime,
|
lastRefreshTime: newestPlayTime,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue