我有很多代理 uri(http 和 socks5),我正在使用 reqwest 通过这些代理发送一些 http 请求,如果他不工作,我想删除一个代理。
for proxy in proxies {
let proxy = match Proxy::all(proxy_url) {
Ok(proxy) => proxy,
Err(e) => {
eprintln!("creating proxy failed! {:?}", e);
continue;
}
};
let client = match Client::builder()
.proxy(proxy)
.build()
let client = match client {
Ok(client) => client,
Err(e) => {
eprintln!("building client failed! {:?}", e);
continue;
}
}
loop {
match client.get(&config.endpoint).send().await {
Ok(_) => {}
Err(e) => {
if e.is_proxy_error() { // this method doesn't exist
eprintln!("Dropping proxy...");
break;
} else {
eprintln!("client error! {:?}", e);
}
}
}
}
}
我有很多种Reqwest::Error
reqwest::Error { kind: Request, url: "http://example.com/", source: hyper::Error(Connect, "socks connect error: Invalid response version") }
reqwest::Error { kind: Request, url: "http://example.com/", source: hyper::Error(Connect, "socks connect error: Proxy server unreachable") }
reqwest::Error { kind: Request, url: "http://example.com/", source: hyper::Error(Connect, "socks connect error: Connection refused") }
reqwest::Error { kind: Request, url: "http://example.com/", source: hyper::Error(Connect, "socks connect error: Connection reset by peer (os error 104)") }
在大多数情况下,错误消息是明确的,但我怎样才能以不同的方式处理它们?reqwest::Error
haveinner
字段是私有的,所以我无法访问他。如果我得到了的来源reqwest::Error
,我只是有一个Box<syn Error>
我不能像对待hyper::Error