aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2022-07-16 13:58:24 -0500
committerMax Isom <[email protected]>2022-07-16 13:59:32 -0500
commite489b10565829c41972e5271d5d56647e499c8a6 (patch)
tree19637f92b890f0ca0b9ce9fa4737d7b076386657 /src/services
parent28bcd4b45e324ad99898423f4ef98300f84e0083 (diff)
downloadmuse-e489b10565829c41972e5271d5d56647e499c8a6.tar.xz
muse-e489b10565829c41972e5271d5d56647e499c8a6.zip
Retry Spotify token refresh
Diffstat (limited to 'src/services')
-rw-r--r--src/services/third-party.ts10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/services/third-party.ts b/src/services/third-party.ts
index e6a8357..706391a 100644
--- a/src/services/third-party.ts
+++ b/src/services/third-party.ts
@@ -1,6 +1,7 @@
import {inject, injectable} from 'inversify';
import SpotifyWebApi from 'spotify-web-api-node';
import Youtube from 'youtube.ts';
+import pRetry from 'p-retry';
import {TYPES} from '../types.js';
import Config from './config.js';
@@ -30,9 +31,10 @@ export default class ThirdParty {
}
private async refreshSpotifyToken() {
- const auth = await this.spotify.clientCredentialsGrant();
- this.spotify.setAccessToken(auth.body.access_token);
-
- this.spotifyTokenTimerId = setTimeout(this.refreshSpotifyToken.bind(this), (auth.body.expires_in / 2) * 1000);
+ await pRetry(async () => {
+ const auth = await this.spotify.clientCredentialsGrant();
+ this.spotify.setAccessToken(auth.body.access_token);
+ this.spotifyTokenTimerId = setTimeout(this.refreshSpotifyToken.bind(this), (auth.body.expires_in / 2) * 1000);
+ }, {retries: 5});
}
}