Skip to content

Commit 96f61bb

Browse files
authored
fix(node-http-handler): throw TimeoutError for Node.js timeouts (#1693)
* fix(node-http-handler): throw TimeoutError for Node.js timeouts * chore: move Node.js timeout error codes to a constant
1 parent 9e58bbb commit 96f61bb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Node.js system error codes that indicate timeout.
3+
*/
4+
export const NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"];

packages/node-http-handler/src/node-http-handler.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { HttpHandlerOptions } from "@aws-sdk/types";
44
import { Agent as hAgent, request as hRequest } from "http";
55
import { Agent as hsAgent, request as hsRequest, RequestOptions } from "https";
66

7+
import { NODEJS_TIMEOUT_ERROR_CODES } from "./constants";
78
import { getTransformedHeaders } from "./get-transformed-headers";
89
import { setConnectionTimeout } from "./set-connection-timeout";
910
import { setSocketTimeout } from "./set-socket-timeout";
@@ -83,7 +84,13 @@ export class NodeHttpHandler implements HttpHandler {
8384
resolve({ response: httpResponse });
8485
});
8586

86-
req.on("error", reject);
87+
req.on("error", (err: Error) => {
88+
if (NODEJS_TIMEOUT_ERROR_CODES.includes((err as any).code)) {
89+
reject(Object.assign(err, { name: "TimeoutError" }));
90+
} else {
91+
reject(err);
92+
}
93+
});
8794

8895
// wire-up any timeout logic
8996
setConnectionTimeout(req, reject, this.connectionTimeout);

0 commit comments

Comments
 (0)