mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
moar better error handling
This commit is contained in:
parent
1192b1b422
commit
5095d73de3
1 changed files with 47 additions and 39 deletions
|
@ -158,57 +158,65 @@ impl ZeroIDC {
|
||||||
.request(http_client);
|
.request(http_client);
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(res) = token_response {
|
if let Some(res) = token_response {
|
||||||
if let Ok(res) = res {
|
match res {
|
||||||
let id_token = res.id_token();
|
Ok(res) => {
|
||||||
|
match res.id_token() {
|
||||||
|
Some(id_token) => {
|
||||||
|
|
||||||
if let Some(id_token) = id_token {
|
let params = [("id_token", id_token.to_string()),("state", "refresh".to_string())];
|
||||||
let params = [("id_token", id_token.to_string()),("state", "refresh".to_string())];
|
let client = reqwest::blocking::Client::new();
|
||||||
let client = reqwest::blocking::Client::new();
|
let r = client.post((*inner_local.lock().unwrap()).auth_endpoint.clone())
|
||||||
let r = client.post((*inner_local.lock().unwrap()).auth_endpoint.clone())
|
.form(¶ms)
|
||||||
.form(¶ms)
|
.send();
|
||||||
.send();
|
|
||||||
|
|
||||||
match r {
|
match r {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
if r.status().is_success() {
|
if r.status().is_success() {
|
||||||
println!("hit url: {}", r.url().as_str());
|
println!("hit url: {}", r.url().as_str());
|
||||||
println!("status: {}", r.status());
|
println!("status: {}", r.status());
|
||||||
|
|
||||||
|
|
||||||
let access_token = res.access_token();
|
let access_token = res.access_token();
|
||||||
let at = access_token.secret();
|
let at = access_token.secret();
|
||||||
let exp = dangerous_insecure_decode::<Exp>(&at);
|
let exp = dangerous_insecure_decode::<Exp>(&at);
|
||||||
|
|
||||||
if let Ok(e) = exp {
|
if let Ok(e) = exp {
|
||||||
(*inner_local.lock().unwrap()).exp_time = e.claims.exp
|
(*inner_local.lock().unwrap()).exp_time = e.claims.exp
|
||||||
|
}
|
||||||
|
|
||||||
|
(*inner_local.lock().unwrap()).access_token = Some(access_token.clone());
|
||||||
|
if let Some(t) = res.refresh_token() {
|
||||||
|
println!("New Refresh Token: {}", t.secret());
|
||||||
|
(*inner_local.lock().unwrap()).refresh_token = Some(t.clone());
|
||||||
|
}
|
||||||
|
println!("Central post succeeded");
|
||||||
|
} else {
|
||||||
|
println!("Central post failed: {}", r.status().to_string());
|
||||||
|
println!("hit url: {}", r.url().as_str());
|
||||||
|
println!("Status: {}", r.status());
|
||||||
|
(*inner_local.lock().unwrap()).exp_time = 0;
|
||||||
|
(*inner_local.lock().unwrap()).running = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("Central post failed: {}", e.to_string());
|
||||||
|
println!("hit url: {}", e.url().unwrap().as_str());
|
||||||
|
println!("Status: {}", e.status().unwrap());
|
||||||
|
// (*inner_local.lock().unwrap()).exp_time = 0;
|
||||||
|
(*inner_local.lock().unwrap()).running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*inner_local.lock().unwrap()).access_token = Some(access_token.clone());
|
|
||||||
if let Some(t) = res.refresh_token() {
|
|
||||||
println!("New Refresh Token: {}", t.secret());
|
|
||||||
(*inner_local.lock().unwrap()).refresh_token = Some(t.clone());
|
|
||||||
}
|
|
||||||
println!("Central post succeeded");
|
|
||||||
} else {
|
|
||||||
println!("Central post failed: {}", r.status().to_string());
|
|
||||||
println!("hit url: {}", r.url().as_str());
|
|
||||||
println!("Status: {}", r.status());
|
|
||||||
(*inner_local.lock().unwrap()).exp_time = 0;
|
|
||||||
(*inner_local.lock().unwrap()).running = false;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
None => {
|
||||||
println!("Central post failed: {}", e.to_string());
|
println!("No id token???");
|
||||||
println!("hit url: {}", e.url().unwrap().as_str());
|
|
||||||
println!("Status: {}", e.status().unwrap());
|
|
||||||
// (*inner_local.lock().unwrap()).exp_time = 0;
|
|
||||||
(*inner_local.lock().unwrap()).running = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("Error posting refresh token: {}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue