fix(runtime): use consistent error handling for user input API
- Change 'not loaded' to 'not found' in submit_user_input and cancel_user_input so map_thread_err correctly maps to 404 - Use map_thread_err in submit_user_input API endpoint for consistent error response (404 for missing thread, 409 for conflict, etc.) instead of always returning 500
This commit is contained in:
@@ -1055,7 +1055,7 @@ async fn submit_user_input(
|
||||
.runtime_threads
|
||||
.submit_user_input(&thread_id, &input_id, response)
|
||||
.await
|
||||
.map_err(|e| ApiError::internal(format!("Failed to submit user input: {e}")))?;
|
||||
.map_err(map_thread_err)?;
|
||||
Ok(Json(SubmitUserInputResponse {
|
||||
ok: true,
|
||||
input_id,
|
||||
|
||||
@@ -841,7 +841,7 @@ impl RuntimeThreadManager {
|
||||
) -> Result<bool> {
|
||||
let active = self.active.lock().await;
|
||||
let Some(state) = active.engines.get(thread_id) else {
|
||||
bail!("thread '{thread_id}' not loaded");
|
||||
bail!("thread '{thread_id}' not found");
|
||||
};
|
||||
state.engine.submit_user_input(input_id, response).await?;
|
||||
Ok(true)
|
||||
@@ -851,7 +851,7 @@ impl RuntimeThreadManager {
|
||||
pub async fn cancel_user_input(&self, thread_id: &str, input_id: &str) -> Result<bool> {
|
||||
let active = self.active.lock().await;
|
||||
let Some(state) = active.engines.get(thread_id) else {
|
||||
bail!("thread '{thread_id}' not loaded");
|
||||
bail!("thread '{thread_id}' not found");
|
||||
};
|
||||
state.engine.cancel_user_input(input_id).await?;
|
||||
Ok(true)
|
||||
|
||||
Reference in New Issue
Block a user