Read-only mirror of github.com/smbcloudXYZ/smbcloud-ascapi.
Mirrored from https://github.com/smbcloudXYZ/smbcloud-ascapi.git
Synced Nov 25, 09:15 UTC
Treat an empty edits reply as no open edit
Amazon answers GET edits with 200 and {} when the app has no open edit. Edit requires an id, so asc amazon edits get failed with a decode error instead of printing null. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.6 <noreply@sigit.si>
Seto Elkahfi committed
Nov 12, 2026 at 12:25 UTC
f021a87f7e319d9c7651534b9e120b3dceeda17b
1 file changed
+26
-1
crates/amazon/src/edit.rs
+26
-1
@@ -33,7 +33,12 @@ impl AmazonClient {
33
detail: response.text().await.unwrap_or_default(),
34
});
35
}
36
- Ok(Some(response.json().await?))
36
+ // Amazon answers 200 with `{}` when the app has no open edit.
37
+ let value: serde_json::Value = response.json().await?;
38
+ if value.get("id").is_none() {
39
+ return Ok(None);
40
+ }
41
+ Ok(Some(serde_json::from_value(value)?))
42
}
43
44
/// Open a new edit. Fails if one is already open.
@@ -62,3 +67,23 @@ impl AmazonClient {
67
Ok(())
68
}
69
}
70
+
71
+#[cfg(test)]
72
+mod tests {
73
+ use crate::auth::Credentials;
74
+ use crate::client::testserver::serve;
75
+ use crate::AmazonClient;
76
+
77
+ const TOKEN_OK: &str = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 26\r\nConnection: close\r\n\r\n{\"access_token\":\"tok-123\"}";
78
+ const EMPTY: &str =
79
+ "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 2\r\nConnection: close\r\n\r\n{}";
80
+
81
+ #[tokio::test]
82
+ async fn an_empty_object_means_no_open_edit() {
83
+ let (base, _seen) = serve(vec![TOKEN_OK, EMPTY]).await;
84
+ let creds = Credentials::from_json(r#"{"client_id":"c","client_secret":"s"}"#).unwrap();
85
+ let client = AmazonClient::new(creds)
86
+ .with_endpoints(&format!("{base}/auth/o2/token"), &format!("{base}/apps"));
87
+ assert!(client.get_edit("APP").await.unwrap().is_none());
88
+ }
89
+}