From 6c8730a9646e324cc2c01b6e86df974a9f39fc64 Mon Sep 17 00:00:00 2001 From: George Fu Date: Sat, 24 Jun 2023 00:33:44 -0400 Subject: [PATCH] fix(node-http-handler): rejoin on error in writeRequestBody (#4880) --- .../src/node-http-handler.spec.ts | 18 ++++++++++++++++++ .../node-http-handler/src/node-http-handler.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/node-http-handler/src/node-http-handler.spec.ts b/packages/node-http-handler/src/node-http-handler.spec.ts index 817008bbb213f..7da3453f16878 100644 --- a/packages/node-http-handler/src/node-http-handler.spec.ts +++ b/packages/node-http-handler/src/node-http-handler.spec.ts @@ -573,6 +573,24 @@ describe("NodeHttpHandler", () => { expect(spy.mock.calls.length).toBe(0); }); + it(`won't throw uncatchable error in writeRequestBody`, async () => { + const nodeHttpHandler = new NodeHttpHandler(); + + await expect( + nodeHttpHandler.handle( + new HttpRequest({ + hostname: "localhost", + method: "GET", + port: (mockHttpsServer.address() as AddressInfo).port, + protocol: "https:", + path: "/", + headers: {}, + body: {}, + }) + ) + ).rejects.toHaveProperty("name", "TypeError"); + }); + it("will destroy the request when aborted", async () => { const mockResponse = { statusCode: 200, diff --git a/packages/node-http-handler/src/node-http-handler.ts b/packages/node-http-handler/src/node-http-handler.ts index 5bd31d47d51cd..288f863a6186f 100644 --- a/packages/node-http-handler/src/node-http-handler.ts +++ b/packages/node-http-handler/src/node-http-handler.ts @@ -189,7 +189,7 @@ export class NodeHttpHandler implements HttpHandler { }); } - writeRequestBodyPromise = writeRequestBody(req, request, this.config.requestTimeout); + writeRequestBodyPromise = writeRequestBody(req, request, this.config.requestTimeout).catch(_reject); }); } }