Skip to content

Commit 5c5270c

Browse files
committed
Attempt to retry commands that fail
1 parent cc983d9 commit 5c5270c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"eslint": "^7.21.0",
2828
"eslint-plugin-github": "^4.1.1",
2929
"prettier": "^2.2.1",
30+
"retry-axios": "^2.4.0",
3031
"streamdeck-typescript": "^3.0.0",
3132
"tsc-watch": "^4.2.9",
3233
"typescript": "^4.2.2",

src/restreamio/restreamio-client.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import {ManagedSettings} from '../settings/managed-settings'
44
import {RestreamioStreamingPlatform, RestreamioToken} from './types'
55
import {SettingsManager} from 'streamdeck-typescript'
66
import createAuthRefreshInterceptor from 'axios-auth-refresh'
7+
import * as rax from 'retry-axios'
78

89
export class RestreamioClient {
910
private managedGlobalSettings: ManagedGlobalSettings
1011
private managedSettings?: ManagedSettings
1112
private authenticatedAxios: AxiosInstance
13+
private unAuthenticatedAxios: AxiosInstance
1214

1315
static fromSettingsManager(
1416
settingsManager: SettingsManager,
@@ -27,6 +29,19 @@ export class RestreamioClient {
2729
this.managedGlobalSettings = managedGlobalSettings
2830
this.managedSettings = managedSettings
2931
this.authenticatedAxios = this.createAuthenticatedAxios()
32+
this.unAuthenticatedAxios = RestreamioClient.createUnauthenticatedAxios()
33+
}
34+
35+
private static createUnauthenticatedAxios(): AxiosInstance {
36+
const unauthenticatedAxios = axios.create()
37+
38+
unauthenticatedAxios.defaults.raxConfig = {
39+
instance: unauthenticatedAxios,
40+
}
41+
42+
rax.attach(unauthenticatedAxios)
43+
44+
return unauthenticatedAxios
3045
}
3146

3247
private createAuthenticatedAxios(): AxiosInstance {
@@ -36,11 +51,9 @@ export class RestreamioClient {
3651
const token = this.getToken()
3752

3853
if (!token) {
39-
console.log('we have no token')
4054
return request
4155
}
4256

43-
console.log('token is', token)
4457
request.headers['Authorization'] = `Bearer ${token.accessToken}`
4558

4659
return request
@@ -58,9 +71,6 @@ export class RestreamioClient {
5871
return axios
5972
.post(refreshUrl, formData)
6073
.then(async tokenRefreshResponse => {
61-
console.log('ok, we refreshed!')
62-
console.log('previous token', this.getToken())
63-
console.log('new token', tokenRefreshResponse)
6474
this.managedGlobalSettings.registerRestreamioAccount(
6575
tokenRefreshResponse.data,
6676
)
@@ -72,6 +82,12 @@ export class RestreamioClient {
7282
})
7383
})
7484

85+
authenticatedAxios.defaults.raxConfig = {
86+
instance: authenticatedAxios,
87+
}
88+
89+
rax.attach(authenticatedAxios)
90+
7591
return authenticatedAxios
7692
}
7793

0 commit comments

Comments
 (0)