From e489b10565829c41972e5271d5d56647e499c8a6 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sat, 16 Jul 2022 13:58:24 -0500 Subject: Retry Spotify token refresh --- src/services/third-party.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/services') 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}); } } -- cgit v1.2.3