@@ -92,7 +92,7 @@ export class Powerwall2Client {
9292
9393 return token ;
9494 } catch ( error ) {
95- this . logger . error ( error ) ;
95+ this . logger . error ( error , "Powerwall2 login error" ) ;
9696
9797 throw new Error ( `Powerwall2 get token error` ) ;
9898 }
@@ -108,6 +108,7 @@ export class Powerwall2Client {
108108 private async get (
109109 url : string ,
110110 options ?: Omit < AxiosRequestConfig < never > , 'headers' > ,
111+ retryCount = 0 ,
111112 ) : Promise < unknown > {
112113 try {
113114 const response = await this . axiosInstance . get < string > ( url , {
@@ -119,18 +120,23 @@ export class Powerwall2Client {
119120
120121 return response . data ;
121122 } catch ( error ) {
122- if ( error instanceof AxiosError ) {
123+ if ( error instanceof AxiosError && error . response ) {
124+ this . logger . error ( error , 'Powerwall2 API get error' )
125+
123126 // permissions error
124127 if (
125- error . response &&
126128 error . response . status >= 400 &&
127- error . response . status < 500
129+ error . response . status < 500 &&
130+ retryCount < 1
128131 ) {
132+ this . logger . info ( "Refreshing Powerwall2 token" )
133+
129134 // refresh token and retry request
130135 this . token = { type : 'none' } ;
131136 await this . getToken ( ) ;
132137
133- return this . get ( url , options ) ;
138+ this . logger . info ( "Retrying Powerwall2 API get" )
139+ return this . get ( url , options , retryCount + 1 ) ;
134140 }
135141
136142 throw error ;
0 commit comments