Skip to content

Commit 3e8573c

Browse files
fix: handle empty object response from /tasks endpoint (#56)
The Redis Cloud API returns an empty object `{}` instead of an empty array `[]` when there are no active tasks. This caused a deserialization error ("invalid type: map, expected a sequence"). Use `get_raw()` and pattern match on the response shape to handle both cases.
1 parent 7fac53f commit 3e8573c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/tasks.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,18 @@ impl TasksHandler {
124124
/// Get tasks
125125
/// Gets a list of all currently running tasks for this account.
126126
///
127+
/// The API returns an array when tasks exist but an empty object `{}` when
128+
/// there are no tasks, so we handle both cases.
129+
///
127130
/// GET /tasks
128131
pub async fn get_all_tasks(&self) -> Result<Vec<TaskStateUpdate>> {
129-
self.client.get("/tasks").await
132+
let value: serde_json::Value = self.client.get_raw("/tasks").await?;
133+
match value {
134+
serde_json::Value::Array(arr) => {
135+
Ok(serde_json::from_value(serde_json::Value::Array(arr))?)
136+
}
137+
_ => Ok(Vec::new()),
138+
}
130139
}
131140

132141
/// Get tasks (raw JSON)

0 commit comments

Comments
 (0)