File tree Expand file tree Collapse file tree 1 file changed +4
-16
lines changed
Expand file tree Collapse file tree 1 file changed +4
-16
lines changed Original file line number Diff line number Diff line change @@ -83,20 +83,11 @@ export const fetchChatbotReplyWithFiles = async (
8383 files : File [ ] ,
8484 signal : AbortSignal ,
8585) : Promise < Message > => {
86- const controller = new AbortController ( ) ;
87- const timeoutId = setTimeout (
88- ( ) => controller . abort ( ) ,
86+ // Combine external signal with timeout using AbortSignal.any()
87+ const timeoutSignal = AbortSignal . timeout (
8988 CHATBOT_API_TIMEOUTS_MS . GENERATE_MESSAGE ,
9089 ) ;
91-
92- if ( signal . aborted ) {
93- controller . abort ( ) ;
94- }
95-
96- const onExternalAbort = ( ) => {
97- controller . abort ( ) ;
98- } ;
99- signal . addEventListener ( "abort" , onExternalAbort ) ;
90+ const combinedSignal = AbortSignal . any ( [ signal , timeoutSignal ] ) ;
10091
10192 try {
10293 const formData = new FormData ( ) ;
@@ -111,7 +102,7 @@ export const fetchChatbotReplyWithFiles = async (
111102 {
112103 method : "POST" ,
113104 body : formData ,
114- signal : controller . signal ,
105+ signal : combinedSignal ,
115106 } ,
116107 ) ;
117108
@@ -138,9 +129,6 @@ export const fetchChatbotReplyWithFiles = async (
138129 console . error ( "API error uploading files:" , error ) ;
139130 }
140131 return createBotMessage ( getChatbotText ( "errorMessage" ) ) ;
141- } finally {
142- clearTimeout ( timeoutId ) ;
143- signal . removeEventListener ( "abort" , onExternalAbort ) ;
144132 }
145133} ;
146134
You can’t perform that action at this time.
0 commit comments