@ai-sdk/provider-utils 4.0.9 → 4.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/handle-fetch-error.ts +33 -0
package/package.json
CHANGED
|
@@ -3,6 +3,29 @@ import { isAbortError } from './is-abort-error';
|
|
|
3
3
|
|
|
4
4
|
const FETCH_FAILED_ERROR_MESSAGES = ['fetch failed', 'failed to fetch'];
|
|
5
5
|
|
|
6
|
+
const BUN_ERROR_CODES = [
|
|
7
|
+
'ConnectionRefused',
|
|
8
|
+
'ConnectionClosed',
|
|
9
|
+
'FailedToOpenSocket',
|
|
10
|
+
'ECONNRESET',
|
|
11
|
+
'ECONNREFUSED',
|
|
12
|
+
'ETIMEDOUT',
|
|
13
|
+
'EPIPE',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
function isBunNetworkError(error: unknown): error is Error & { code?: string } {
|
|
17
|
+
if (!(error instanceof Error)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const code = (error as any).code;
|
|
22
|
+
if (typeof code === 'string' && BUN_ERROR_CODES.includes(code)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
6
29
|
export function handleFetchError({
|
|
7
30
|
error,
|
|
8
31
|
url,
|
|
@@ -35,5 +58,15 @@ export function handleFetchError({
|
|
|
35
58
|
}
|
|
36
59
|
}
|
|
37
60
|
|
|
61
|
+
if (isBunNetworkError(error)) {
|
|
62
|
+
return new APICallError({
|
|
63
|
+
message: `Cannot connect to API: ${error.message}`,
|
|
64
|
+
cause: error,
|
|
65
|
+
url,
|
|
66
|
+
requestBodyValues,
|
|
67
|
+
isRetryable: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
38
71
|
return error;
|
|
39
72
|
}
|