File tree Expand file tree Collapse file tree
xdk-gen/templates/typescript Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -116,20 +116,28 @@ export class HttpClient {
116116
117117 // Handle timeout
118118 let signal = options.signal;
119+ let timeoutId: ReturnType<typeof setTimeout > | undefined;
120+
119121 if (options.timeout && options.timeout > 0 && !signal) {
120122 const controller = new AbortController();
121- setTimeout(() => controller.abort(), options.timeout);
123+ timeoutId = setTimeout(() => controller.abort(), options.timeout);
122124 signal = controller.signal;
123125 }
124126
125- const response = await this.fetch(url, {
126- method: options.method || 'GET',
127- headers: options.headers as any,
128- body: body as any,
129- signal: signal,
130- });
131-
132- return response as HttpResponse;
127+ try {
128+ const response = await this.fetch(url, {
129+ method: options.method || 'GET',
130+ headers: options.headers as any,
131+ body: body as any,
132+ signal: signal,
133+ });
134+
135+ return response as HttpResponse;
136+ } finally {
137+ if (timeoutId !== undefined) {
138+ clearTimeout(timeoutId);
139+ }
140+ }
133141 }
134142
135143 /**
You can’t perform that action at this time.
0 commit comments