@@ -89,8 +89,18 @@ class HttpClient extends Processor {
8989 const method = super . getProperty ( ns . trn . method , 'GET' ) . toUpperCase ( )
9090 const headers = super . getProperty ( ns . trn . headers , { } )
9191 const body = super . getProperty ( ns . trn . body , null )
92+ const timeout = super . getProperty ( ns . trn . timeout , 30000 ) // Default 30s timeout
9293
9394 const options = { method, headers }
95+
96+ // Add timeout using AbortController
97+ if ( timeout ) {
98+ const controller = new AbortController ( )
99+ options . signal = controller . signal
100+ options . controller = controller
101+ options . timeout = parseInt ( timeout )
102+ }
103+
94104 if ( body && ( method === 'POST' || method === 'PUT' || method === 'PATCH' ) ) {
95105 options . body = typeof body === 'string' ? body : JSON . stringify ( body )
96106 if ( ! headers [ 'Content-Type' ] ) {
@@ -107,7 +117,24 @@ class HttpClient extends Processor {
107117 * @returns {Promise<Response> }
108118 */
109119 async _sendRequest ( requestOptions ) {
110- const { url, ...options } = requestOptions
120+ const { url, timeout, controller, ...options } = requestOptions
121+
122+ // Handle timeout
123+ if ( timeout && controller ) {
124+ const timeoutId = setTimeout ( ( ) => {
125+ controller . abort ( )
126+ } , timeout )
127+
128+ try {
129+ const response = await fetch ( url , options )
130+ clearTimeout ( timeoutId )
131+ return response
132+ } catch ( error ) {
133+ clearTimeout ( timeoutId )
134+ throw error
135+ }
136+ }
137+
111138 return fetch ( url , options )
112139 }
113140
0 commit comments