Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-dao committed Feb 20, 2025
1 parent 74c942c commit 552c5e9
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ check-nodejs:
@if command -v node > /dev/null; then \
NODE_VERSION=$(shell node --version | sed -E 's/v//g'); \
IFS='.' read -r -a NODE_VERSION_ARRAY <<< "$$NODE_VERSION"; \
if [ "$${NODE_VERSION_ARRAY[0]}" -ge 20 ]; then \
if [ "$${NODE_VERSION_ARRAY[0]}" -ge 22 ]; then \
echo "$(BLUE)Node.js $$NODE_VERSION is already installed.$(RESET)"; \
else \
echo "$(RED)Node.js 20.x or later is required. Please install Node.js 20.x or later to continue.$(RESET)"; \
echo "$(RED)Node.js 22.x or later is required. Please install Node.js 22.x or later to continue.$(RESET)"; \
exit 1; \
fi; \
else \
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ i18n
.init({
fallbackLng: "en",
debug: import.meta.env.NODE_ENV === "development",
load: "languageOnly"

Check failure on line 29 in frontend/src/i18n/index.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Insert `,`
});

export default i18n;
8 changes: 5 additions & 3 deletions openhands/server/routes/conversation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Request
from fastapi import APIRouter, Request, status
from fastapi.responses import JSONResponse

from openhands.core.logger import openhands_logger as logger
Expand Down Expand Up @@ -40,11 +40,13 @@ async def get_vscode_url(request: Request):
runtime: Runtime = request.state.conversation.runtime
logger.debug(f'Runtime type: {type(runtime)}')
logger.debug(f'Runtime VSCode URL: {runtime.vscode_url}')
return JSONResponse(status_code=200, content={'vscode_url': runtime.vscode_url})
return JSONResponse(
status_code=status.HTTP_200_OK, content={'vscode_url': runtime.vscode_url}
)
except Exception as e:
logger.error(f'Error getting VSCode URL: {e}')
return JSONResponse(
status_code=500,
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
'vscode_url': None,
'error': f'Error getting VSCode URL: {e}',
Expand Down
7 changes: 4 additions & 3 deletions openhands/server/routes/feedback.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Request
from fastapi import APIRouter, Request, status
from fastapi.responses import JSONResponse

from openhands.core.logger import openhands_logger as logger
Expand Down Expand Up @@ -50,9 +50,10 @@ async def submit_feedback(request: Request, conversation_id: str):
)
try:
feedback_data = await call_sync_from_async(store_feedback, feedback)
return JSONResponse(status_code=200, content=feedback_data)
return JSONResponse(status_code=status.HTTP_200_OK, content=feedback_data)
except Exception as e:
logger.error(f'Error submitting feedback: {e}')
return JSONResponse(
status_code=500, content={'error': 'Failed to submit feedback'}
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={'error': 'Failed to submit feedback'},
)
18 changes: 9 additions & 9 deletions openhands/server/routes/github.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, status
from fastapi.responses import JSONResponse
from pydantic import SecretStr

Expand Down Expand Up @@ -33,13 +33,13 @@ async def get_github_repositories(
except GhAuthenticationError as e:
return JSONResponse(
content=str(e),
status_code=401,
status_code=status.HTTP_401_UNAUTHORIZED,
)

except GHUnknownException as e:
return JSONResponse(
content=str(e),
status_code=500,
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)


Expand All @@ -56,13 +56,13 @@ async def get_github_user(
except GhAuthenticationError as e:
return JSONResponse(
content=str(e),
status_code=401,
status_code=status.HTTP_401_UNAUTHORIZED,
)

except GHUnknownException as e:
return JSONResponse(
content=str(e),
status_code=500,
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)


Expand All @@ -79,13 +79,13 @@ async def get_github_installation_ids(
except GhAuthenticationError as e:
return JSONResponse(
content=str(e),
status_code=401,
status_code=status.HTTP_401_UNAUTHORIZED,
)

except GHUnknownException as e:
return JSONResponse(
content=str(e),
status_code=500,
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)


Expand All @@ -108,11 +108,11 @@ async def search_github_repositories(
except GhAuthenticationError as e:
return JSONResponse(
content=str(e),
status_code=401,
status_code=status.HTTP_401_UNAUTHORIZED,
)

except GHUnknownException as e:
return JSONResponse(
content=str(e),
status_code=500,
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
6 changes: 3 additions & 3 deletions openhands/server/routes/manage_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime, timezone
from typing import Callable

from fastapi import APIRouter, Body, Request
from fastapi import APIRouter, Body, Request, status
from fastapi.responses import JSONResponse
from pydantic import BaseModel, SecretStr

Expand Down Expand Up @@ -164,7 +164,7 @@ async def new_conversation(request: Request, data: InitSessionRequest):
'message': str(e),
'msg_id': 'CONFIGURATION$SETTINGS_NOT_FOUND',
},
status_code=400,
status_code=status.HTTP_400_BAD_REQUEST,
)

except LLMAuthenticationError as e:
Expand All @@ -174,7 +174,7 @@ async def new_conversation(request: Request, data: InitSessionRequest):
'message': str(e),
'msg_id': 'STATUS$ERROR_LLM_AUTHENTICATION',
},
status_code=400,
status_code=status.HTTP_400_BAD_REQUEST,
)


Expand Down
6 changes: 5 additions & 1 deletion openhands/server/routes/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
APIRouter,
HTTPException,
Request,
status,
)

app = APIRouter(prefix='/api/conversations/{conversation_id}')
Expand All @@ -23,7 +24,10 @@ async def security_api(request: Request):
HTTPException: If the security analyzer is not initialized.
"""
if not request.state.conversation.security_analyzer:
raise HTTPException(status_code=404, detail='Security analyzer not initialized')
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail='Security analyzer not initialized',
)

return await request.state.conversation.security_analyzer.handle_api_request(
request
Expand Down
8 changes: 5 additions & 3 deletions openhands/server/routes/trajectory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Request
from fastapi import APIRouter, Request, status
from fastapi.responses import JSONResponse

from openhands.core.logger import openhands_logger as logger
Expand Down Expand Up @@ -28,11 +28,13 @@ async def get_trajectory(request: Request):
trajectory = []
async for event in async_stream:
trajectory.append(event_to_trajectory(event))
return JSONResponse(status_code=200, content={'trajectory': trajectory})
return JSONResponse(
status_code=status.HTTP_200_OK, content={'trajectory': trajectory}
)
except Exception as e:
logger.error(f'Error getting trajectory: {e}', exc_info=True)
return JSONResponse(
status_code=500,
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
'trajectory': None,
'error': f'Error getting trajectory: {e}',
Expand Down

0 comments on commit 552c5e9

Please sign in to comment.