sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

UnhandledPromiseRejectionWarning on RequestError: write EPIPE with got 11 #1233

Closed javi11 closed 4 years ago

javi11 commented 4 years ago

Describe the bug

Actual behavior

When the connection is closed by the server with an EPIPE an UnhandledPromiseRejectionWarning is thrown with

(node:39306) UnhandledPromiseRejectionWarning: RequestError: write EPIPE
    at ClientRequest.<anonymous> (/Users/redacted/redacted/redacted/node_modules/got/dist/source/core/index.js:764:25)
    at Object.onceWrapper (events.js:417:26)
    at ClientRequest.emit (events.js:322:22)
    at ClientRequest.origin.emit (/Users/redacted/redacted/redacted/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20)
    at TLSSocket.socketErrorListener (_http_client.js:426:9)
    at TLSSocket.emit (events.js:310:20)
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at onwriteError (_stream_writable.js:424:5)
    at onwrite (_stream_writable.js:445:5)
    at internal/streams/destroy.js:50:7
    at TLSSocket.Socket._destroy (net.js:677:5)
    at TLSSocket.destroy (internal/streams/destroy.js:38:8)
    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:93:12)
    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16)
(node:39306) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

The message is:

 RequestError: Cannot read property 'method' of undefined

Expected behavior

As in GOT 10 the error should be propagated but without an UnhandledPromiseRejectionWarning

Code to reproduce

I really do know how to reproduce it since is happening only on my home network, but still i think it should not throw an UnhandledPromiseRejectionWarning.

Checklist

szmarczak commented 4 years ago

Please include a full reproducible example.

javi11 commented 4 years ago

Closing was a problem with my network and code implementation :P sorry

szmarczak commented 4 years ago

np