Skip to content

Commit af7f742

Browse files
edouardparisclaude
andcommitted
fix(jade): improve PIN server handshake reliability
- Handle multiple fallback URLs when primary PIN server fails - Add proper Accept header to PIN server requests - Provide detailed error messages for debugging handshake issues - Match Python jadepy library behavior more closely This should resolve handshake failures when the first PIN server URL is unavailable or returns errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4d5234f commit af7f742

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

src/jade/pinserver.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,46 @@ impl PinServerClient {
2121
where
2222
D: serde::de::DeserializeOwned,
2323
{
24-
let url = match &req.urls {
25-
api::PinServerUrls::Array(urls) => urls.first().ok_or(Error::NoUrlProvided)?,
26-
api::PinServerUrls::Object { url, .. } => url,
24+
let urls = match &req.urls {
25+
api::PinServerUrls::Array(urls) => {
26+
if urls.is_empty() {
27+
return Err(Error::NoUrlProvided);
28+
}
29+
urls.clone()
30+
}
31+
api::PinServerUrls::Object { url, .. } => vec![url.clone()],
2732
};
2833

29-
let res = self.client.post(url).json(&req.data).send().await?;
34+
let mut last_error = None;
35+
36+
for url in urls {
37+
let res = self
38+
.client
39+
.post(&url)
40+
.header("Accept", &req.accept)
41+
.json(&req.data)
42+
.send()
43+
.await;
3044

31-
if res.status().is_success() {
32-
res.json().await.map_err(Error::from)
33-
} else {
34-
Err(Error::Server(format!("{:?}", res)))
45+
match res {
46+
Ok(response) if response.status().is_success() => {
47+
return response.json().await.map_err(Error::from);
48+
}
49+
Ok(response) => {
50+
last_error = Some(Error::Server(format!(
51+
"HTTP {} from {}: {:?}",
52+
response.status(),
53+
url,
54+
response
55+
)));
56+
}
57+
Err(e) => {
58+
last_error = Some(Error::Client(e));
59+
}
60+
}
3561
}
62+
63+
Err(last_error.unwrap_or(Error::NoUrlProvided))
3664
}
3765
}
3866

0 commit comments

Comments
 (0)