Skip to content

Commit 5bc2f31

Browse files
fix(api): return INVALID_PATH for invalid project sessions path
1 parent 1e53d72 commit 5bc2f31

3 files changed

Lines changed: 6 additions & 14 deletions

File tree

api/projects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from flask import Blueprint, current_app
44

55
from api._flask_types import FlaskReturn, json_error, json_response
6+
from api.error_codes import ErrorCode, error_response
67
from models.project import ProjectSessionRowDict, SessionListItemDict
78
from models.session import SessionDict
89
from utils.session_path import get_claude_projects_dir, list_projects, list_sessions, safe_join
@@ -76,7 +77,7 @@ def get_project_sessions(project_name: str) -> FlaskReturn:
7677
try:
7778
project_dir = safe_join(base, project_name)
7879
except ValueError:
79-
return json_response([]), 400
80+
return error_response(ErrorCode.INVALID_PATH, "Invalid path", 400)
8081
sessions = list_sessions(project_dir)
8182
# Add summary preview for each session
8283
from utils.jsonl_parser import parse_session

docs/api-reference.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,7 @@ Most `/api/*` error responses use this shape:
2525
}
2626
```
2727

28-
**Exception (no `{error, code}` body):**
29-
30-
| Endpoint | Status | Body |
31-
|----------|--------|------|
32-
| `GET /api/projects/<project_name>/sessions` | 400 | `[]` (empty JSON array) when `project_name` fails path validation |
33-
34-
*Legacy response shape — not the long-term contract. New clients should not treat bare `[]` as the intended error format; migration to structured `{error, code}` with `INVALID_PATH` is planned.*
35-
36-
All other documented error paths below use the structured envelope.
28+
All documented error paths below use the structured envelope.
3729

3830
Extra fields may appear for specific codes (for example `since` on invalid bulk-export mode).
3931

@@ -174,7 +166,7 @@ Lists sessions in one project with summary fields for the workspace sidebar. Ski
174166

175167
| Status | `code` | When |
176168
|--------|--------|------|
177-
| 400 | | Invalid `project_name` (path escape). **Body is `[]`** (legacy — see [Error envelope](#error-envelope) exception); not a structured error |
169+
| 400 | `INVALID_PATH` | Invalid `project_name` (path escape) |
178170

179171
```bash
180172
curl -s "http://127.0.0.1:5000/api/projects/F--boost-capy/sessions" | jq '.[0]'

tests/test_api_routes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ def test_search_limit_capped_at_max(client):
6161
assert len(results) <= 500
6262

6363

64-
def test_project_sessions_invalid_path_returns_400_empty_list(client):
64+
def test_project_sessions_invalid_path_returns_invalid_path(client):
6565
resp = client.get("/api/projects/../../outside/sessions")
66-
assert resp.status_code == 400
67-
assert resp.get_json() == []
66+
assert_error_response(resp, expected_code="INVALID_PATH")
6867

6968

7069
def test_export_state_defaults(client_empty):

0 commit comments

Comments
 (0)