|
import pRetry, { AbortError } from 'p-retry'; |
|
import pTimeout from 'p-timeout'; |
|
|
|
export async function withQwenTimeout<T>( |
|
fn: () => Promise<T>, |
|
{ totalTimeout = 70_000, retries = 2 } = {} |
|
): Promise<T> { |
|
return pRetry( |
|
async () => { |
|
try { |
|
return await pTimeout(fn(), { milliseconds: totalTimeout }); |
|
} catch (error) { |
|
|
|
if (error && typeof error === 'object' && !(error instanceof Error)) { |
|
const errorMessage = error.message || error.toString() || 'Network connection error'; |
|
throw new Error(errorMessage); |
|
} |
|
throw error; |
|
} |
|
}, |
|
{ |
|
retries, |
|
onFailedAttempt: (error) => { |
|
console.error(`qwen3 attempt #${error.attemptNumber} failed: ${error.message}`); |
|
if (error.retriesLeft === 0) { |
|
console.error('qwen3 max retries reached, giving up'); |
|
} |
|
} |
|
} |
|
); |
|
} |