ofetch
ofetch copied to clipboard
How to get a specify error timeout?
Environment
ofetch: 1.3.3 nodejs: 19.7.0 nuxt: 3.8.0
Reproduction
use $fetch to call an API, when fetch timeout, promise error:
error.code: undefined
error.message: [GET] "https://api.themoviedb.org/3/movie/575264?language=zh-CN": <no response>
JSON.stringify(error): {"name":"FetchError"}
error.cause: TypeError: fetch failed
Describe the bug
FetchError: [GET] "https://api.themoviedb.org/3/movie/575264?language=zh-CN": <no response> fetch failed
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async $fetchRaw2 (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:228:14)
... 3 lines matching cause stack trace ...
at async Server.toNodeHandle (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1840:7) {
[cause]: TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11413:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async $fetchRaw2 (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:219:26)
at async $fetchRaw2 (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:228:14)
at async $fetch2 (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:261:15)
at <anonymous> (C:\Users\ASUS\workspace\nas-tools\server\api\tmdb\[...].ts:123:1)
at async Object.handler (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1630:19)
at async Server.toNodeHandle (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:1840:7) {
cause: ConnectTimeoutError: Connect Timeout Error
at onConnectTimeout (node:internal/deps/undici/undici:8380:28)
at node:internal/deps/undici/undici:8338:50
at Immediate._onImmediate (node:internal/deps/undici/undici:8367:37)
at process.processImmediate (node:internal/timers:475:21) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}
}
server side logs have some information: ConnectTimeoutError and UND_ERR_CONNECT_TIMEOUT are useful, how can I get this infomation?
Additional context
No response
Logs
No response
I got same problem...
+1
@pi0 help