@@ -204,7 +204,7 @@ export const process_file = async (params: {
204204 cancel_token ?: CancelToken
205205 on_chunk ?: ( tokens_per_second : number , total_tokens : number ) => void
206206 on_thinking_chunk ?: ( text : string ) => void
207- } ) : Promise < string | null > => {
207+ } ) : Promise < string > => {
208208 Logger . info ( {
209209 function_name : 'process_file' ,
210210 message : 'start' ,
@@ -228,62 +228,62 @@ export const process_file = async (params: {
228228
229229 apply_reasoning_effort ( body , params . provider , params . reasoning_effort )
230230
231- try {
232- const result = await make_api_request ( {
233- endpoint_url : params . endpoint_url ,
234- api_key : params . api_key ,
235- body,
236- cancellation_token : params . cancel_token ,
237- on_chunk : params . on_chunk ,
238- on_thinking_chunk : params . on_thinking_chunk
239- } )
240-
241- const refactored_content = result ?. response
242- if ( ! refactored_content ) {
243- vscode . window . showErrorMessage (
244- dictionary . error_message . APPLYING_CHANGES_FAILED_EMPTY_RESPONSE (
245- params . file_path
246- )
247- )
248- Logger . error ( {
249- function_name : 'process_file' ,
250- message : 'API request returned empty response' ,
251- data : params . file_path
231+ let attempt = 0
232+ // eslint-disable-next-line no-constant-condition
233+ while ( true ) {
234+ attempt ++
235+ try {
236+ const result = await make_api_request ( {
237+ endpoint_url : params . endpoint_url ,
238+ api_key : params . api_key ,
239+ body,
240+ cancellation_token : params . cancel_token ,
241+ on_chunk : params . on_chunk ,
242+ on_thinking_chunk : params . on_thinking_chunk
252243 } )
253- return null
254- }
255244
256- const cleaned_content = cleanup_api_response ( {
257- content : refactored_content
258- } )
259- Logger . info ( {
260- function_name : 'process_file' ,
261- message : 'API response received and cleaned' ,
262- data : {
263- file_path : params . file_path ,
264- response_length : cleaned_content ?. length
245+ const refactored_content = result ?. response
246+ if ( ! refactored_content ) {
247+ Logger . error ( {
248+ function_name : 'process_file' ,
249+ message : 'API request returned empty response' ,
250+ data : { file_path : params . file_path , attempt }
251+ } )
252+ throw new Error ( 'API request returned empty response' )
265253 }
266- } )
267- return cleaned_content
268- } catch ( error : any ) {
269- if ( axios . isCancel ( error ) ) {
254+
255+ const cleaned_content = cleanup_api_response ( {
256+ content : refactored_content
257+ } )
270258 Logger . info ( {
271259 function_name : 'process_file' ,
272- message : 'Request cancelled' ,
273- data : params . file_path
260+ message : 'API response received and cleaned' ,
261+ data : {
262+ file_path : params . file_path ,
263+ response_length : cleaned_content ?. length
264+ }
274265 } )
275- throw error
276- }
266+ return cleaned_content
267+ } catch ( error : any ) {
268+ if ( axios . isCancel ( error ) ) {
269+ Logger . info ( {
270+ function_name : 'process_file' ,
271+ message : 'Request cancelled' ,
272+ data : params . file_path
273+ } )
274+ throw error
275+ }
277276
278- Logger . error ( {
279- function_name : 'process_file' ,
280- message : 'Refactoring error' ,
281- data : { error, file_path : params . file_path }
282- } )
283- console . error ( `Refactoring error for ${ params . file_path } :` , error )
284- vscode . window . showErrorMessage (
285- dictionary . error_message . ERROR_DURING_REFACTORING ( params . file_path )
286- )
287- return null
277+ Logger . error ( {
278+ function_name : 'process_file' ,
279+ message : `Refactoring error (attempt ${ attempt } )` ,
280+ data : { error, file_path : params . file_path }
281+ } )
282+ console . error (
283+ `Refactoring error for ${ params . file_path } (attempt ${ attempt } ):` ,
284+ error
285+ )
286+ await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
287+ }
288288 }
289289}
0 commit comments