Description
Four API endpoints return HTTP 500 Internal Server Error when a resource is simply not found. These should return 404 Not Found since the request is valid but the referenced resource doesn't exist.
Affected endpoints
1. POST /api/ccl/eval — no policy found
curl -X POST http://127.0.0.1:9200/api/ccl/eval \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"paranetId":"testing","name":"nonexistent"}'
# Returns: HTTP 500 {"error":"No approved policy found for testing/nonexistent"}
# Expected: HTTP 404
2. POST /api/verify — batch not found
curl -X POST http://127.0.0.1:9200/api/verify \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"contextGraphId":"testing","verifiedMemoryId":"test","batchId":"1"}'
# Returns: HTTP 500 {"error":"Batch 1 not found in context graph testing"}
# Expected: HTTP 404
3. POST /api/ccl/policy/approve — policy not found
curl -X POST http://127.0.0.1:9200/api/ccl/policy/approve \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"paranetId":"testing","policyUri":"nonexistent"}'
# Returns: HTTP 500 {"error":"CCL policy not found: nonexistent"}
# Expected: HTTP 404
4. POST /api/ccl/policy/revoke — no active binding
curl -X POST http://127.0.0.1:9200/api/ccl/policy/revoke \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"paranetId":"testing","policyUri":"nonexistent"}'
# Returns: HTTP 500 {"error":"No active CCL policy binding found for nonexistent in paranet \"testing\"."}
# Expected: HTTP 404
Root cause
All four handlers call agent.* methods that throw when the resource isn't found. There's no try/catch wrapping these calls in daemon.ts, so the generic error handler catches the throw and returns 500.
Suggested fix
Wrap each agent method call in a try/catch and return 404 for "not found" errors. For example:
try {
const result = await agent.evaluateCclPolicy({ paranetId, name, ... });
return jsonResponse(res, 200, result);
} catch (err: any) {
if (err.message?.includes('not found') || err.message?.includes('No approved policy')) {
return jsonResponse(res, 404, { error: err.message });
}
throw err;
}
Environment
- Branch:
v10-rc
- Commit:
1c92a69a
- Node: v23.3.0
Description
Four API endpoints return HTTP 500 Internal Server Error when a resource is simply not found. These should return 404 Not Found since the request is valid but the referenced resource doesn't exist.
Affected endpoints
1.
POST /api/ccl/eval— no policy found2.
POST /api/verify— batch not found3.
POST /api/ccl/policy/approve— policy not found4.
POST /api/ccl/policy/revoke— no active bindingRoot cause
All four handlers call
agent.*methods that throw when the resource isn't found. There's no try/catch wrapping these calls indaemon.ts, so the generic error handler catches the throw and returns 500.Suggested fix
Wrap each agent method call in a try/catch and return 404 for "not found" errors. For example:
Environment
v10-rc1c92a69a