Skip to content

Commit db517b2

Browse files
committed
RDBC-908 Improve robustness of createAgent by refining undici import logic and enhancing variable naming consistency
1 parent 1d06b8c commit db517b2

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/Http/RequestExecutor.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -378,28 +378,28 @@ export class RequestExecutor implements IDisposable {
378378
}
379379
}
380380

381-
private static async createAgent(options: Agent.Options) {
382-
try {
383-
let AgentInstance;
384-
381+
private static async createAgent(options: Agent.Options) {
385382
try {
386-
const undiciModule = await import(importFix("undici"));
387-
AgentInstance = undiciModule.Agent;
388-
} catch (err) {
389-
const undiciModule = await import("undici");
390-
AgentInstance = undiciModule.Agent;
391-
}
383+
let UndiciAgent;
392384

393-
if (!AgentInstance) {
394-
throw new Error("Agent not found in undici module");
395-
}
385+
try {
386+
const undiciModule = await import(importFix("undici"));
387+
UndiciAgent = undiciModule.Agent;
388+
} catch (err) {
389+
const undiciModule = await import("undici");
390+
UndiciAgent = undiciModule.Agent;
391+
}
396392

397-
return new AgentInstance(options);
398-
} catch (err) {
399-
// If we can't import undici - we might be in cloudflare env - simply return no-agent.
400-
return null;
393+
if (!UndiciAgent) {
394+
throw new Error("Agent not found in undici module");
395+
}
396+
397+
return new UndiciAgent(options);
398+
} catch (err) {
399+
// If we can't import undici - we might be in cloudflare env - simply return no-agent.
400+
return null;
401+
}
401402
}
402-
}
403403

404404
public getTopologyNodes(): ServerNode[] {
405405
const topology = this.getTopology();

0 commit comments

Comments
 (0)