π OpenHands: AI-Driven Development
modify all api response to the same format (JSONResponse with status_code and content set) (#1175)
Xia Zhenhua60a92a07c15c
diff --git a/opendevin/server/listen.py b/opendevin/server/listen.pyindex fa3fa724cf..3b43dc6465 100644--- a/opendevin/server/listen.py+++ b/opendevin/server/listen.py@@ -2,7 +2,7 @@ import uuidfrom pathlib import Pathimport litellm-from fastapi import Depends, FastAPI, WebSocket, Response+from fastapi import Depends, FastAPI, WebSocketfrom fastapi.middleware.cors import CORSMiddlewarefrom fastapi.responses import RedirectResponsefrom fastapi.security import HTTPAuthorizationCredentials, HTTPBearer@@ -69,10 +69,7 @@ async def get_token("""sid = get_sid_from_token(credentials.credentials) or str(uuid.uuid4())token = sign_token({'sid': sid})- return JSONResponse(- status_code=status.HTTP_200_OK,- content={'token': token},- )+ return {'token': token}@app.get('/api/messages')@@ -84,10 +81,7 @@ async def get_messages(if sid != '':data = message_stack.get_messages(sid)- return JSONResponse(- status_code=status.HTTP_200_OK,- content={'messages': data},- )+ return {'messages': data}@app.get('/api/messages/total')@@ -95,10 +89,7 @@ async def get_message_total(credentials: HTTPAuthorizationCredentials = Depends(security_scheme),):sid = get_sid_from_token(credentials.credentials)- return JSONResponse(- status_code=status.HTTP_200_OK,- content={'msg_total': message_stack.get_message_total(sid)},- )+ return {'msg_total': message_stack.get_message_total(sid)}@app.delete('/api/messages')@@ -107,10 +98,7 @@ async def del_messages():sid = get_sid_from_token(credentials.credentials)message_stack.del_messages(sid)- return JSONResponse(- status_code=status.HTTP_200_OK,- content={'ok': True},- )+ return {'ok': True}@app.get('/api/configurations')@@ -134,7 +122,10 @@ def select_file(file: str):except Exception as e:logger.error(f'Error opening file {file}: {e}', exc_info=False)error_msg = f'Error opening file: {e}'- return Response(f'{{"error": "{error_msg}"}}', status_code=500)+ return JSONResponse(+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,+ content={'error': error_msg},+ )return {'code': content}