api: add structured context for read path errors

This commit is contained in:
a.tolmachev
2026-04-19 21:50:28 +00:00
parent ba10bf805d
commit 84555aaf70
2 changed files with 108 additions and 14 deletions
+36 -12
View File
@@ -1372,7 +1372,10 @@ impl AdminService {
.get_invocation_log(workspace_id, log_id)
.await?
.ok_or_else(|| {
ApiError::not_found(format!("invocation log {} was not found", log_id.as_str()))
ApiError::not_found_with_context(
format!("invocation log {} was not found", log_id.as_str()),
json!({ "log_id": log_id.as_str() }),
)
})
}
@@ -1744,7 +1747,10 @@ impl AdminService {
.get_operation_summary(workspace_id, operation_id)
.await?
.ok_or_else(|| {
ApiError::not_found(format!("operation {} was not found", operation_id.as_str()))
ApiError::not_found_with_context(
format!("operation {} was not found", operation_id.as_str()),
json!({ "operation_id": operation_id.as_str() }),
)
})?;
let agent_refs = self
.registry
@@ -1790,10 +1796,16 @@ impl AdminService {
.get_operation_version(workspace_id, operation_id, version)
.await?
.ok_or_else(|| {
ApiError::not_found(format!(
"operation version {version} for {} was not found",
operation_id.as_str()
))
ApiError::not_found_with_context(
format!(
"operation version {version} for {} was not found",
operation_id.as_str()
),
json!({
"operation_id": operation_id.as_str(),
"version": version,
}),
)
})
}
@@ -2487,7 +2499,10 @@ impl AdminService {
.await?
.map(|record| record.secret)
.ok_or_else(|| {
ApiError::not_found(format!("secret {} was not found", secret_id.as_str()))
ApiError::not_found_with_context(
format!("secret {} was not found", secret_id.as_str()),
json!({ "secret_id": secret_id.as_str() }),
)
})
}
@@ -2657,7 +2672,10 @@ impl AdminService {
.get_agent_summary(workspace_id, agent_id)
.await?
.ok_or_else(|| {
ApiError::not_found(format!("agent {} was not found", agent_id.as_str()))
ApiError::not_found_with_context(
format!("agent {} was not found", agent_id.as_str()),
json!({ "agent_id": agent_id.as_str() }),
)
})?;
let version = self
.get_agent_version(workspace_id, agent_id, summary.current_draft_version)
@@ -2710,10 +2728,16 @@ impl AdminService {
.get_agent_version(workspace_id, agent_id, version)
.await?
.ok_or_else(|| {
ApiError::not_found(format!(
"agent version {version} for {} was not found",
agent_id.as_str()
))
ApiError::not_found_with_context(
format!(
"agent version {version} for {} was not found",
agent_id.as_str()
),
json!({
"agent_id": agent_id.as_str(),
"version": version,
}),
)
})
}