unjs / unjs/ofetch

How to get a specify error timeout?

Open
#310 5 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5.4k
Forks
195
PR merge metrics
No merged PRs in 30d

Description

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/ofetch@1.3.3/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/h3@1.8.2/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/ofetch@1.3.3/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:219:26)
      at async $fetchRaw2 (file:///xxx/node_modules/.pnpm/ofetch@1.3.3/node_modules/ofetch/dist/shared/ofetch.00501375.mjs:228:14)
      at async $fetch2 (file:///xxx/node_modules/.pnpm/ofetch@1.3.3/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/h3@1.8.2/node_modules/h3/dist/index.mjs:1630:19)
      at async Server.toNodeHandle (file:///xxx/node_modules/.pnpm/h3@1.8.2/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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the $fetchRaw2 and $fetch2 entry points shown in the stack trace, then reproduce the timeout under Node.js 19.7.0. Inspect how FetchError exposes its cause; done means callers can access useful timeout details such as ConnectTimeoutError and UND_ERR_CONNECT_TIMEOUT.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.