@@ -104,7 +104,8 @@ export class RingRestClient {
104
104
headers : {
105
105
'content-type' : 'application/json' ,
106
106
'2fa-support' : 'true' ,
107
- '2fa-code' : twoFactorAuthCode || ''
107
+ '2fa-code' : twoFactorAuthCode || '' ,
108
+ hardware_id : hardwareId
108
109
}
109
110
} )
110
111
@@ -172,7 +173,14 @@ export class RingRestClient {
172
173
try {
173
174
return await this . fetchNewSession ( authToken )
174
175
} catch ( e ) {
175
- if ( e && e . response && e . response . status === 429 ) {
176
+ const response = e . response || { }
177
+
178
+ if ( response . status === 401 ) {
179
+ this . refreshAuth ( )
180
+ return this . getSession ( )
181
+ }
182
+
183
+ if ( response . status === 429 ) {
176
184
const retryAfter = e . response . headers [ 'retry-after' ] ,
177
185
waitSeconds = isNaN ( retryAfter ) ? 200 : Number . parseInt ( retryAfter )
178
186
@@ -204,18 +212,19 @@ export class RingRestClient {
204
212
json ?: boolean
205
213
responseType ?: ResponseType
206
214
} ) : Promise < T & ExtendedResponse > {
207
- await this . sessionPromise
208
- const { method, url, data, json, responseType } = options ,
209
- authTokenResponse = await this . authPromise ,
210
- headers : { [ key : string ] : string } = {
211
- 'content-type' : json
212
- ? 'application/json'
213
- : 'application/x-www-form-urlencoded' ,
214
- authorization : `Bearer ${ authTokenResponse . access_token } ` ,
215
- hardware_id : hardwareId
216
- }
215
+ const { method, url, data, json, responseType } = options
217
216
218
217
try {
218
+ await this . sessionPromise
219
+ const authTokenResponse = await this . authPromise ,
220
+ headers : { [ key : string ] : string } = {
221
+ 'content-type' : json
222
+ ? 'application/json'
223
+ : 'application/x-www-form-urlencoded' ,
224
+ authorization : `Bearer ${ authTokenResponse . access_token } ` ,
225
+ hardware_id : hardwareId
226
+ }
227
+
219
228
return await requestWithRetry < T > ( {
220
229
method : method || 'GET' ,
221
230
url,
0 commit comments