@@ -41,6 +41,7 @@ async def handle_http_request(request_id: str, payload: dict, cancel_token):
4141
4242from ..decorators import get_capability_meta
4343from ..errors import AstrBotError
44+ from ._errors import wrap_client_exception
4445from ._proxy import CapabilityProxy
4546
4647
@@ -116,16 +117,23 @@ async def register_api(
116117 if methods is None :
117118 methods = ["GET" ]
118119 resolved_handler = _resolve_handler_capability (handler_capability , handler )
119-
120- await self ._proxy .call (
121- "http.register_api" ,
122- {
123- "route" : route ,
124- "methods" : methods ,
125- "handler_capability" : resolved_handler ,
126- "description" : description ,
127- },
128- )
120+ try :
121+ await self ._proxy .call (
122+ "http.register_api" ,
123+ {
124+ "route" : route ,
125+ "methods" : methods ,
126+ "handler_capability" : resolved_handler ,
127+ "description" : description ,
128+ },
129+ )
130+ except Exception as exc :
131+ raise wrap_client_exception (
132+ client_name = "HTTPClient" ,
133+ method_name = "register_api" ,
134+ details = f"route={ route !r} , methods={ list (methods )!r} " ,
135+ exc = exc ,
136+ ) from exc
129137
130138 async def unregister_api (
131139 self , route : str , methods : list [str ] | None = None
@@ -141,11 +149,18 @@ async def unregister_api(
141149 """
142150 if methods is None :
143151 methods = []
144-
145- await self ._proxy .call (
146- "http.unregister_api" ,
147- {"route" : route , "methods" : methods },
148- )
152+ try :
153+ await self ._proxy .call (
154+ "http.unregister_api" ,
155+ {"route" : route , "methods" : methods },
156+ )
157+ except Exception as exc :
158+ raise wrap_client_exception (
159+ client_name = "HTTPClient" ,
160+ method_name = "unregister_api" ,
161+ details = f"route={ route !r} , methods={ list (methods )!r} " ,
162+ exc = exc ,
163+ ) from exc
149164
150165 async def list_apis (self ) -> list [dict [str , Any ]]:
151166 """列出当前插件注册的所有 API。
@@ -158,8 +173,15 @@ async def list_apis(self) -> list[dict[str, Any]]:
158173 for api in apis:
159174 print(f"{api['route']}: {api['methods']}")
160175 """
161- output = await self ._proxy .call (
162- "http.list_apis" ,
163- {},
164- )
176+ try :
177+ output = await self ._proxy .call (
178+ "http.list_apis" ,
179+ {},
180+ )
181+ except Exception as exc :
182+ raise wrap_client_exception (
183+ client_name = "HTTPClient" ,
184+ method_name = "list_apis" ,
185+ exc = exc ,
186+ ) from exc
165187 return output .get ("apis" , [])
0 commit comments