Skip to content

How to get a specify error timeout? #310

@maicss

Description

@maicss

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions