MCPcopy
hub / github.com/OpenBMB/ChatDev / handle_mac_exception

Function handle_mac_exception

utils/error_handler.py:67–96  ·  view source on GitHub ↗

Handle DevAll exceptions and return standardized error response.

(request: Request, exc: MACException)

Source from the content-addressed store, hash-verified

65
66
67async def handle_mac_exception(request: Request, exc: MACException) -> JSONResponse:
68 """Handle DevAll exceptions and return standardized error response."""
69 logger = get_server_logger()
70
71 # Log the error
72 logger.log_exception(
73 exc,
74 f"DevAll exception occurred: {exc.error_code} - {exc.message}",
75 correlation_id=getattr(request.state, 'correlation_id', None),
76 url=str(request.url),
77 method=request.method
78 )
79
80 # Determine the HTTP status code
81 status_code = ERROR_CODE_TO_STATUS.get(exc.error_code, 500)
82
83 # Prepare response data
84 response_data = {
85 "error": {
86 "code": exc.error_code,
87 "message": exc.message,
88 "details": exc.details
89 },
90 "timestamp": exc.__dict__.get('_timestamp', __import__('datetime').datetime.utcnow().isoformat())
91 }
92
93 return JSONResponse(
94 status_code=status_code,
95 content=jsonable_encoder(response_data)
96 )
97
98
99async def handle_general_exception(request: Request, exc: Exception) -> JSONResponse:

Calls 3

get_server_loggerFunction · 0.90
log_exceptionMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected