@@ -871,8 +871,7 @@ def save_image_to_cache(base64_data, filename, image_info, ignore_info=False):
871871 return url , info
872872
873873
874- async def response_json (response ):
875- text = await response .text ()
874+ def http_error_to_message (response , text ):
876875 if response .status >= 400 :
877876 message = "HTTP " + str (response .status ) + " " + response .reason
878877 _dbg (f"HTTP { response .status } { response .reason } \n { dict (response .headers )} \n { text } " )
@@ -885,6 +884,13 @@ async def response_json(response):
885884 except Exception :
886885 if text :
887886 message += ": " + text [:100 ]
887+ return message
888+
889+
890+ async def response_json (response ):
891+ text = await response .text ()
892+ if response .status >= 400 :
893+ message = http_error_to_message (response , text )
888894 raise Exception (message )
889895 response .raise_for_status ()
890896 body = json .loads (text )
@@ -2233,7 +2239,7 @@ async def get_text(url):
22332239 async with session .get (url ) as resp :
22342240 text = await resp .text ()
22352241 if resp .status >= 400 :
2236- raise HTTPError ( resp . status , reason = resp . reason , body = text , headers = dict ( resp . headers ))
2242+ raise Exception ( http_error_to_message ( resp , text ))
22372243 return text
22382244
22392245
@@ -2958,7 +2964,7 @@ async def on_chat_error(self, e: Exception, context: Dict[str, Any]):
29582964 for filter_func in self .chat_error_filters :
29592965 try :
29602966 task = filter_func (e , context )
2961- if asyncio . isfuture (task ):
2967+ if inspect . iscoroutine (task ):
29622968 await task
29632969 except Exception as e :
29642970 _err ("chat error filter failed" , e )
0 commit comments