try make requests more robust
Browse files- src/lib/utils/qwenTimeout.ts +12 -1
src/lib/utils/qwenTimeout.ts
CHANGED
|
@@ -6,7 +6,18 @@ export async function withQwenTimeout<T>(
|
|
| 6 |
{ totalTimeout = 180_000, retries = 2 } = {}
|
| 7 |
): Promise<T> {
|
| 8 |
return pRetry(
|
| 9 |
-
() =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
{
|
| 11 |
retries,
|
| 12 |
onFailedAttempt: (error) => {
|
|
|
|
| 6 |
{ totalTimeout = 180_000, retries = 2 } = {}
|
| 7 |
): Promise<T> {
|
| 8 |
return pRetry(
|
| 9 |
+
async () => {
|
| 10 |
+
try {
|
| 11 |
+
return await pTimeout(fn(), { milliseconds: totalTimeout });
|
| 12 |
+
} catch (error) {
|
| 13 |
+
// Convert non-Error objects to proper Error objects for p-retry
|
| 14 |
+
if (error && typeof error === 'object' && !(error instanceof Error)) {
|
| 15 |
+
const errorMessage = error.message || error.toString() || 'Network connection error';
|
| 16 |
+
throw new Error(errorMessage);
|
| 17 |
+
}
|
| 18 |
+
throw error;
|
| 19 |
+
}
|
| 20 |
+
},
|
| 21 |
{
|
| 22 |
retries,
|
| 23 |
onFailedAttempt: (error) => {
|