Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/backend/database/service/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async def sync_user_with_token_data(self, user_id: UUID, token_data: Dict[str, A
roles=token_data.get("roles", [])
)
except ValueError as e:
print(f"Error creating user: {e}")
# Handle case where user might have been created in a race condition
if "already exists" in str(e):
user_data = await self.get_user(user_id)
Expand Down
1 change: 1 addition & 0 deletions src/backend/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def _handle_auth_error(self, detail: str, status_code: int = 401) -> Optional[No
"""Handle authentication errors based on auto_error setting"""
if self.auto_error:
headers = {"WWW-Authenticate": "Bearer"} if status_code == 401 else None
print(f"Authentication error: {detail}")
raise HTTPException(
status_code=status_code,
detail=detail,
Expand Down
1 change: 1 addition & 0 deletions src/backend/routers/auth_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async def callback(
):
session_id = request.cookies.get('session_id')
if not session_id:
print("No session ID found")
raise HTTPException(status_code=400, detail="No session")

# Exchange code for token
Expand Down
15 changes: 10 additions & 5 deletions src/backend/routers/pad_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@


@pad_router.post("")
async def save_canvas(
async def save_pad(
data: Dict[str, Any],
user: UserSession = Depends(require_auth),
pad_service: PadService = Depends(get_pad_service),
backup_service: BackupService = Depends(get_backup_service),
):
"""Save canvas data for the authenticated user"""
"""Save pad data for the authenticated user"""
try:
# Check if user already has a pad
user_pads = await pad_service.get_pads_by_owner(user.id)
Expand All @@ -44,17 +44,18 @@ async def save_canvas(

return {"status": "success"}
except Exception as e:
print(f"Error saving pad data: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to save canvas data: {str(e)}")


@pad_router.get("")
async def get_canvas(
async def get_pad(
user: UserSession = Depends(require_auth),
pad_service: PadService = Depends(get_pad_service),
template_pad_service: TemplatePadService = Depends(get_template_pad_service),
backup_service: BackupService = Depends(get_backup_service)
):
"""Get canvas data for the authenticated user"""
"""Get pad data for the authenticated user"""
try:
# Get user's pads
user_pads = await pad_service.get_pads_by_owner(user.id)
Expand All @@ -73,7 +74,8 @@ async def get_canvas(
# Return the first pad's data (assuming one pad per user for now)
return user_pads[0]["data"]
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to get canvas data: {str(e)}")
print(f"Error getting pad data: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to get pad data: {str(e)}")


@pad_router.post("/from-template/{name}")
Expand Down Expand Up @@ -110,8 +112,10 @@ async def create_pad_from_template(

return pad
except ValueError as e:
print(f"Error creating pad from template: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))
except Exception as e:
print(f"Error creating pad from template: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to create pad from template: {str(e)}")


Expand Down Expand Up @@ -141,4 +145,5 @@ async def get_recent_canvas_backups(

return {"backups": backups}
except Exception as e:
print(f"Error getting canvas backups: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to get canvas backups: {str(e)}")
9 changes: 9 additions & 0 deletions src/backend/routers/template_pad_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async def create_template_pad(
)
return template_pad
except ValueError as e:
print(f"Error creating template pad: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))


Expand All @@ -39,6 +40,7 @@ async def get_all_template_pads(
template_pads = await template_pad_service.get_all_templates()
return template_pads
except Exception as e:
print(f"Error getting template pads: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to get template pads: {str(e)}")


Expand All @@ -51,6 +53,7 @@ async def get_template_pad(
"""Get a specific template pad by name"""
template_pad = await template_pad_service.get_template_by_name(name)
if not template_pad:
print(f"Template pad not found: {name}")
raise HTTPException(status_code=404, detail="Template pad not found")

return template_pad
Expand All @@ -67,10 +70,12 @@ async def update_template_pad(
try:
updated_template = await template_pad_service.update_template(name, data)
if not updated_template:
print(f"Template pad not found: {name}")
raise HTTPException(status_code=404, detail="Template pad not found")

return updated_template
except ValueError as e:
print(f"Error updating template pad: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))


Expand All @@ -85,10 +90,12 @@ async def update_template_pad_data(
try:
updated_template = await template_pad_service.update_template_data(name, data)
if not updated_template:
print(f"Template pad not found: {name}")
raise HTTPException(status_code=404, detail="Template pad not found")

return updated_template
except ValueError as e:
print(f"Error updating template pad data: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))


Expand All @@ -102,8 +109,10 @@ async def delete_template_pad(
try:
success = await template_pad_service.delete_template(name)
if not success:
print(f"Template pad not found: {name}")
raise HTTPException(status_code=404, detail="Template pad not found")

return {"status": "success", "message": "Template pad deleted successfully"}
except ValueError as e:
print(f"Error deleting template pad: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))
2 changes: 2 additions & 0 deletions src/backend/routers/user_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async def create_user(
)
return user
except ValueError as e:
print(f"Error creating user: {str(e)}")
raise HTTPException(status_code=400, detail=str(e))


Expand Down Expand Up @@ -74,6 +75,7 @@ async def get_user_info(
# Sync user with token data
user_data = await user_service.sync_user_with_token_data(user.id, token_data)
except Exception as e:
print(f"Error syncing user data: {str(e)}")
raise HTTPException(
status_code=500,
detail=f"Error syncing user data: {e}"
Expand Down
5 changes: 5 additions & 0 deletions src/backend/routers/workspace_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ async def get_workspace_state(

coder_user: dict = coder_api.get_user_by_email(user.email)
if not coder_user:
print(f"Coder user not found for user {user.email} ({user.id})")
raise HTTPException(status_code=404, detail=f"Coder user not found for user {user.email} ({user.id})")

coder_username: str = coder_user.get('username', None)
if not coder_username:
print(f"Coder username not found for user {user.email} ({user.id})")
raise HTTPException(status_code=404, detail=f"Coder username not found for user {user.email} ({user.id})")

workspace: dict = coder_api.get_workspace_status_for_user(coder_username)
if not workspace:
print(f"Coder workspace not found for user {user.email} ({user.id})")
raise HTTPException(status_code=404, detail=f"Coder Workspace not found for user {user.email} ({user.id})")

latest_build: dict = workspace.get('latest_build', {})
Expand Down Expand Up @@ -68,6 +71,7 @@ async def start_workspace(
response = coder_api.start_workspace(workspace.id)
return JSONResponse(content=response)
except Exception as e:
print(f"Error starting workspace: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))


Expand All @@ -86,4 +90,5 @@ async def stop_workspace(
response = coder_api.stop_workspace(workspace.id)
return JSONResponse(content=response)
except Exception as e:
print(f"Error stopping workspace: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))