yym68686 commited on
Commit
82cedb5
·
1 Parent(s): d738fa5

Fix httpx.RemoteProtocolError error

Browse files
Files changed (1) hide show
  1. utils.py +8 -7
utils.py CHANGED
@@ -1,5 +1,6 @@
1
  import json
2
  from fastapi import HTTPException
 
3
 
4
  from log_config import logger
5
 
@@ -103,17 +104,17 @@ async def error_handling_wrapper(generator, status_code=200):
103
  # 如果不是错误,创建一个新的生成器,首先yield第一个项,然后yield剩余的项
104
  async def new_generator():
105
  yield ensure_string(first_item)
106
- async for item in generator:
107
- yield ensure_string(item)
 
 
 
 
108
 
109
  return new_generator()
 
110
  except StopAsyncIteration:
111
  raise HTTPException(status_code=status_code, detail="data: {'error': 'No data returned'}")
112
- except Exception as e:
113
- logger.error(f"error_handling_wrapper Exception: {str(e)}")
114
- import traceback
115
- logger.error(f"error_handling_wrapper Exception: {traceback.print_exc()}")
116
- raise HTTPException(status_code=status_code, detail="data: {'error': 'No data returned'}")
117
 
118
  def post_all_models(token, config, api_list):
119
  all_models = []
 
1
  import json
2
  from fastapi import HTTPException
3
+ import httpx
4
 
5
  from log_config import logger
6
 
 
104
  # 如果不是错误,创建一个新的生成器,首先yield第一个项,然后yield剩余的项
105
  async def new_generator():
106
  yield ensure_string(first_item)
107
+ try:
108
+ async for item in generator:
109
+ yield ensure_string(item)
110
+ except httpx.RemoteProtocolError as e:
111
+ logger.error(f"Remote protocol error occurred: {e}")
112
+ raise StopAsyncIteration
113
 
114
  return new_generator()
115
+
116
  except StopAsyncIteration:
117
  raise HTTPException(status_code=status_code, detail="data: {'error': 'No data returned'}")
 
 
 
 
 
118
 
119
  def post_all_models(token, config, api_list):
120
  all_models = []