(apiCall: () => Promise<T>)
| 195 | } |
| 196 | |
| 197 | private async callApiWithRetry<T>(apiCall: () => Promise<T>): Promise<T> { |
| 198 | try { |
| 199 | return await apiCall() |
| 200 | } catch (error: any) { |
| 201 | if (error.status === 401) { |
| 202 | // Token expired, refresh and retry |
| 203 | this.credentials = await this.refreshAccessToken(this.credentials!) |
| 204 | const client = this.ensureClient() |
| 205 | client.apiKey = this.credentials.access_token |
| 206 | client.baseURL = this.getBaseUrl(this.credentials) |
| 207 | return await apiCall() |
| 208 | } else { |
| 209 | throw error |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | override async *createMessage( |
| 215 | systemPrompt: string, |
no test coverage detected