( taskId: string, token: string, maxRetries = 3, retryDelayMs = 2000, )
| 193 | * retries a few times. Ported from the extension's fetchTaskTitle. |
| 194 | */ |
| 195 | export async function fetchTaskTitle( |
| 196 | taskId: string, |
| 197 | token: string, |
| 198 | maxRetries = 3, |
| 199 | retryDelayMs = 2000, |
| 200 | ): Promise<string | null> { |
| 201 | if (!token) return null; |
| 202 | const url = getUrlFromToken( |
| 203 | `https://api.matterai.so/axoncode/meta/${taskId}`, |
| 204 | token, |
| 205 | ); |
| 206 | |
| 207 | for (let attempt = 1; attempt <= maxRetries; attempt++) { |
| 208 | try { |
| 209 | const response = await fetch(url, { |
| 210 | headers: { Authorization: `Bearer ${token}` }, |
| 211 | signal: AbortSignal.timeout(5000), |
| 212 | }); |
| 213 | if (response.ok) { |
| 214 | const data: unknown = await response.json().catch(() => undefined); |
| 215 | const title = sanitizeTitle(data); |
| 216 | if (title) return title; |
| 217 | } |
| 218 | } catch { |
| 219 | // network/timeout: fall through to retry |
| 220 | } |
| 221 | if (attempt < maxRetries) { |
| 222 | await new Promise((resolve) => setTimeout(resolve, retryDelayMs)); |
| 223 | } |
| 224 | } |
| 225 | return null; |
| 226 | } |
| 227 | |
| 228 | export async function fetchBalance( |
| 229 | token: string, |
no test coverage detected