AndrewBarba / fetch-http2

Native http2 fetch implementation for Node.js
MIT License
5 stars 1 forks source link

Fixed 'error' is undefined when the request is timed out #3

Closed RodolfoGS closed 1 year ago

RodolfoGS commented 1 year ago

When your request is timed out, the variable error in your try catch is undefined.

Reproducible Example 1:

try {
  await fetch('https://httpbin.org/json', {
    timeout: 1
  })
} catch (error) {
  console.log(error) // error: undefined
}

Reproducible Example 2: Run the test that I created in this PR without the fix applied

The function req.setTimeout does not return any parameter in their callback, also you need to close the request with status NGHTTP2_CANCEL

Source: https://nodejs.org/api/http2.html#http2streamsettimeoutmsecs-callback