mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-10 07:38:04 -05:00
feat(backend): Propagate error arguments on RPC exceptions (#9533)
<!-- Clearly explain the need for these changes: --> ### Changes 🏗️ Exception can contain more than message, so we propagate the whole args as long as it is serializable. ### Checklist 📋 #### For code changes: - [ ] I have clearly listed my changes in the PR description - [ ] I have made a test plan - [ ] I have tested my changes according to the test plan: <!-- Put your test plan here: --> - [ ] ... <details> <summary>Example test plan</summary> - [ ] Create from scratch and execute an agent with at least 3 blocks - [ ] Import an agent from file upload, and confirm it executes correctly - [ ] Upload agent to marketplace - [ ] Import an agent from marketplace and confirm it executes correctly - [ ] Edit an agent from monitor, and confirm it executes correctly </details> #### For configuration changes: - [ ] `.env.example` is updated or already compatible with my changes - [ ] `docker-compose.yml` is updated or already compatible with my changes - [ ] I have included a list of my configuration changes in the PR description (under **Changes**) <details> <summary>Examples of configuration changes</summary> - Changing ports - Adding new services that need to communicate with each other - Secrets or environment variable changes - New or infrastructure changes such as databases </details>
This commit is contained in:
@@ -240,6 +240,21 @@ class BaseAppService(AppProcess, ABC):
|
||||
logger.info(f"[{self.__class__.__name__}] ⏳ Disconnecting RabbitMQ...")
|
||||
|
||||
|
||||
class RemoteCallError(BaseModel):
|
||||
type: str = "RemoteCallError"
|
||||
args: Optional[Tuple[Any]] = None
|
||||
|
||||
|
||||
EXCEPTION_MAPPING = {
|
||||
e.__name__: e
|
||||
for e in [
|
||||
ValueError,
|
||||
TimeoutError,
|
||||
ConnectionError,
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
class FastApiAppService(BaseAppService, ABC):
|
||||
fastapi_app: FastAPI
|
||||
|
||||
@@ -248,9 +263,12 @@ class FastApiAppService(BaseAppService, ABC):
|
||||
def handler(request: Request, exc: Exception):
|
||||
if log_error:
|
||||
logger.exception(f"{request.method} {request.url.path} failed: {exc}")
|
||||
return responses.Response(
|
||||
content=str(exc),
|
||||
return responses.JSONResponse(
|
||||
status_code=status_code,
|
||||
content=RemoteCallError(
|
||||
type=str(exc.__class__.__name__),
|
||||
args=exc.args or (str(exc),),
|
||||
).model_dump(),
|
||||
)
|
||||
|
||||
return handler
|
||||
@@ -422,7 +440,8 @@ def fastapi_get_service_client(service_type: Type[AS]) -> AS:
|
||||
return response.json()
|
||||
except httpx.HTTPStatusError as e:
|
||||
logger.error(f"HTTP error in {method_name}: {e.response.text}")
|
||||
raise Exception(e.response.text) from e
|
||||
error = RemoteCallError.model_validate(e.response.json(), strict=False)
|
||||
raise EXCEPTION_MAPPING.get(error.type, Exception)(*error.args)
|
||||
|
||||
def close(self):
|
||||
self.client.close()
|
||||
|
||||
Reference in New Issue
Block a user