diff --git a/index-scheduler/src/error.rs b/index-scheduler/src/error.rs index 8c3804a05..7a91dfbd3 100644 --- a/index-scheduler/src/error.rs +++ b/index-scheduler/src/error.rs @@ -27,6 +27,10 @@ pub enum Error { SwapDuplicateIndexesFound(Vec), #[error("Corrupted dump.")] CorruptedDump, + #[error( + "Tasks uids must be a comma-separated list of numbers. `{task_uids}` is invalid {error_message}" + )] + InvalidTaskUids { task_uids: String, error_message: String }, #[error("Task `{0}` not found.")] TaskNotFound(TaskId), #[error("Query parameters to filter the tasks to delete are missing. Available query parameters are: `uid`, `indexUid`, `status`, `type`.")] @@ -71,6 +75,7 @@ impl ErrorCode for Error { Error::IndexAlreadyExists(_) => Code::IndexAlreadyExists, Error::SwapDuplicateIndexesFound(_) => Code::DuplicateIndexFound, Error::SwapDuplicateIndexFound(_) => Code::DuplicateIndexFound, + Error::InvalidTaskUids { .. } => Code::InvalidTaskUid, Error::TaskNotFound(_) => Code::TaskNotFound, Error::TaskDeletionWithEmptyQuery => Code::TaskDeletionWithEmptyQuery, Error::TaskCancelationWithEmptyQuery => Code::TaskCancelationWithEmptyQuery, diff --git a/meilisearch-http/src/routes/tasks.rs b/meilisearch-http/src/routes/tasks.rs index 0c9a49a3c..500df8716 100644 --- a/meilisearch-http/src/routes/tasks.rs +++ b/meilisearch-http/src/routes/tasks.rs @@ -211,7 +211,7 @@ pub struct TaskDateQuery { pub struct TasksFilterQuery { #[serde(rename = "type")] kind: Option>>, - uid: Option>, + uid: Option>, status: Option>>, index_uid: Option>>, #[serde(default = "DEFAULT_LIMIT")] @@ -457,15 +457,25 @@ async fn get_tasks( async fn get_task( index_scheduler: GuardedData, Data>, - task_id: web::Path, + task_uid: web::Path, req: HttpRequest, analytics: web::Data, ) -> Result { - let task_id = task_id.into_inner(); + let task_uid_string = task_uid.into_inner(); + let task_uid: TaskId = match task_uid_string.parse() { + Ok(id) => id, + Err(e) => { + return Err(index_scheduler::Error::InvalidTaskUids { + task_uids: task_uid_string, + error_message: e.to_string(), + } + .into()) + } + }; analytics.publish("Tasks Seen".to_string(), json!({ "per_task_uid": true }), Some(&req)); - let query = index_scheduler::Query { uid: Some(vec![task_id]), ..Query::default() }; + let query = index_scheduler::Query { uid: Some(vec![task_uid]), ..Query::default() }; if let Some(task) = index_scheduler .get_tasks_from_authorized_indexes( @@ -477,7 +487,7 @@ async fn get_task( let task_view = TaskView::from_task(task); Ok(HttpResponse::Ok().json(task_view)) } else { - Err(index_scheduler::Error::TaskNotFound(task_id).into()) + Err(index_scheduler::Error::TaskNotFound(task_uid).into()) } } diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index d902bc82a..37f7a8a33 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -147,6 +147,7 @@ pub enum Code { MissingMasterKey, NoSpaceLeftOnDevice, DumpNotFound, + InvalidTaskUid, TaskNotFound, TaskDeletionWithEmptyQuery, TaskCancelationWithEmptyQuery, @@ -238,6 +239,7 @@ impl Code { MissingMasterKey => { ErrCode::authentication("missing_master_key", StatusCode::UNAUTHORIZED) } + InvalidTaskUid => ErrCode::invalid("invalid_task_uid", StatusCode::BAD_REQUEST), TaskNotFound => ErrCode::invalid("task_not_found", StatusCode::NOT_FOUND), TaskDeletionWithEmptyQuery => { ErrCode::invalid("missing_task_filters", StatusCode::BAD_REQUEST)