Skip to content

Commit ab5ba3a

Browse files
committed
fixing lint types errors
1 parent 2c63a41 commit ab5ba3a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/http-client.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class HttpClient {
2222
#abortController;
2323
#agent;
2424
#breaker;
25+
#followRedirects;
2526
#hasFallback = false;
2627
#logger;
2728
#throwOn400;
@@ -51,6 +52,7 @@ export default class HttpClient {
5152
this.#throwOn500 = throwOn500;
5253

5354
this.#abortController = abortController;
55+
this.#followRedirects = followRedirects;
5456

5557
// TODO; Can we avoid bind here in a nice way?????
5658
this.#breaker = new Opossum(this.#request.bind(this), {
@@ -63,23 +65,17 @@ export default class HttpClient {
6365
timeout,
6466
});
6567

66-
const { redirect } = interceptors;
67-
let agent = new Agent({
68+
this.#agent = new Agent({
6869
keepAliveMaxTimeout,
6970
keepAliveTimeout,
7071
connections,
7172
pipelining,
7273
});
73-
if (followRedirects) {
74-
agent = agent.compose(
75-
redirect({ maxRedirections: 1, throwOnMaxRedirects: true }),
76-
);
77-
}
78-
this.#agent = agent;
7974

8075
if (fallback) {
8176
this.#hasFallback = true;
8277
if (typeof fallback === 'string') {
78+
//@ts-ignore
8379
this.#fallback(() => fallback);
8480
} else {
8581
this.#fallback(fallback);
@@ -88,8 +84,16 @@ export default class HttpClient {
8884
}
8985

9086
async #request(options = {}) {
87+
if (this.#followRedirects) {
88+
const { redirect } = interceptors;
89+
options.dispatcher = this.#agent.compose(
90+
redirect({ maxRedirections: 1 }),
91+
);
92+
} else {
93+
options.dispatcher = this.#agent;
94+
}
95+
9196
const { statusCode, headers, trailers, body } = await request({
92-
dispatcher: this.#agent,
9397
...options,
9498
});
9599

0 commit comments

Comments
 (0)