fix(api): continue crawling when access token refresh fails for one user

This commit is contained in:
Julian Tölle 2021-05-20 19:19:24 +02:00
parent 721f979cc8
commit 0c2188c4d4

View file

@ -50,6 +50,7 @@ export class SpotifyService {
playHistory = await this.spotifyApi.getRecentlyPlayedTracks(user.spotify);
} catch (err) {
if (err.response && err.response.status === 401 && retryOnExpiredToken) {
try {
const accessToken = await this.spotifyAuth.refreshAccessToken(
user.spotify
);
@ -58,6 +59,11 @@ export class SpotifyService {
accessToken,
});
await this.crawlListensForUser(user, false);
} catch (errFromAuth) {
this.logger.error(
`Refreshing access token failed for user "${user.id}": ${errFromAuth}`
);
}
} else {
// TODO sent to sentry
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.
return;
}
@ -111,7 +117,7 @@ export class SpotifyService {
* The variable will still be set, in case we want to add the functionality
* again.
*/
this.usersService.updateSpotifyConnection(user, {
await this.usersService.updateSpotifyConnection(user, {
...user.spotify,
lastRefreshTime: newestPlayTime,
});