api: add structured context for usage and session errors

This commit is contained in:
a.tolmachev
2026-04-19 21:54:41 +00:00
parent 84555aaf70
commit b9ab17d1d3
2 changed files with 100 additions and 20 deletions
+23 -20
View File
@@ -1439,10 +1439,13 @@ impl AdminService {
)
.await?
.ok_or_else(|| {
ApiError::not_found(format!(
"usage for operation {} was not found",
operation_id.as_str()
))
ApiError::not_found_with_context(
format!(
"usage for operation {} was not found",
operation_id.as_str()
),
json!({ "operation_id": operation_id.as_str() }),
)
})
}
@@ -1470,10 +1473,10 @@ impl AdminService {
)
.await?
.ok_or_else(|| {
ApiError::not_found(format!(
"usage for agent {} was not found",
agent_id.as_str()
))
ApiError::not_found_with_context(
format!("usage for agent {} was not found", agent_id.as_str()),
json!({ "agent_id": agent_id.as_str() }),
)
})
}
@@ -1534,10 +1537,10 @@ impl AdminService {
.get_stream_session(session_id)
.await?
.ok_or_else(|| {
ApiError::not_found(format!(
"stream session {} was not found",
session_id.as_str()
))
ApiError::not_found_with_context(
format!("stream session {} was not found", session_id.as_str()),
json!({ "session_id": session_id.as_str() }),
)
})?;
ensure_stream_session_workspace(&session, workspace_id)?;
@@ -1556,10 +1559,10 @@ impl AdminService {
.get_stream_session(session_id)
.await?
.ok_or_else(|| {
ApiError::not_found(format!(
"stream session {} was not found",
session_id.as_str()
))
ApiError::not_found_with_context(
format!("stream session {} was not found", session_id.as_str()),
json!({ "session_id": session_id.as_str() }),
)
})?;
ensure_stream_session_workspace(&session, workspace_id)?;
self.registry
@@ -1570,10 +1573,10 @@ impl AdminService {
.get_stream_session(session_id)
.await?
.ok_or_else(|| {
ApiError::not_found(format!(
"stream session {} was not found",
session_id.as_str()
))
ApiError::not_found_with_context(
format!("stream session {} was not found", session_id.as_str()),
json!({ "session_id": session_id.as_str() }),
)
})?;
Ok(stream_session_detail_view(updated))