Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions xdk-gen/templates/typescript/http_client.j2
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,28 @@ export class HttpClient {

// Handle timeout
let signal = options.signal;
let timeoutId: ReturnType<typeof setTimeout> | undefined;

if (options.timeout && options.timeout > 0 && !signal) {
const controller = new AbortController();
setTimeout(() => controller.abort(), options.timeout);
timeoutId = setTimeout(() => controller.abort(), options.timeout);
signal = controller.signal;
}

const response = await this.fetch(url, {
method: options.method || 'GET',
headers: options.headers as any,
body: body as any,
signal: signal,
});

return response as HttpResponse;
try {
const response = await this.fetch(url, {
method: options.method || 'GET',
headers: options.headers as any,
body: body as any,
signal: signal,
});

return response as HttpResponse;
} finally {
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
}
}

/**
Expand Down