Skip to content

Commit

Permalink
fixing lint types errors
Browse files Browse the repository at this point in the history
  • Loading branch information
leftieFriele committed Oct 31, 2024
1 parent 2c63a41 commit ab5ba3a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class HttpClient {
#abortController;
#agent;
#breaker;
#followRedirects;
#hasFallback = false;
#logger;
#throwOn400;
Expand Down Expand Up @@ -51,6 +52,7 @@ export default class HttpClient {
this.#throwOn500 = throwOn500;

this.#abortController = abortController;
this.#followRedirects = followRedirects;

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

const { redirect } = interceptors;
let agent = new Agent({
this.#agent = new Agent({
keepAliveMaxTimeout,
keepAliveTimeout,
connections,
pipelining,
});
if (followRedirects) {
agent = agent.compose(
redirect({ maxRedirections: 1, throwOnMaxRedirects: true }),
);
}
this.#agent = agent;

if (fallback) {
this.#hasFallback = true;
if (typeof fallback === 'string') {
//@ts-ignore
this.#fallback(() => fallback);
} else {
this.#fallback(fallback);
Expand All @@ -88,8 +84,16 @@ export default class HttpClient {
}

async #request(options = {}) {
if (this.#followRedirects) {
const { redirect } = interceptors;
options.dispatcher = this.#agent.compose(
redirect({ maxRedirections: 1 }),
);
} else {
options.dispatcher = this.#agent;
}

const { statusCode, headers, trailers, body } = await request({
dispatcher: this.#agent,
...options,
});

Expand Down

0 comments on commit ab5ba3a

Please sign in to comment.