From e2cd8b331c7558688b0ec5b807a76ca104f40f84 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 8 Jan 2019 15:37:47 -0800 Subject: better rust auth error handling/responses --- rust/src/auth.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'rust') diff --git a/rust/src/auth.rs b/rust/src/auth.rs index f9b8d7b9..acee147e 100644 --- a/rust/src/auth.rs +++ b/rust/src/auth.rs @@ -241,21 +241,21 @@ impl AuthConfectionary { let raw = BASE64.decode(s.as_bytes())?; let mac = match Macaroon::deserialize(&raw) { Ok(m) => m, - Err(_e) => { + Err(e) => { // TODO: should be "chaining" here - //bail!("macaroon deserialize error: {:?}", e), return Err( - ErrorKind::InvalidCredentials("macaroon deserialize error".to_string()).into(), + ErrorKind::InvalidCredentials( + format!("macaroon deserialize error: {:?}", e)).into(), ); } }; let mac = match mac.validate() { Ok(m) => m, - Err(_e) => { + Err(e) => { // TODO: should be "chaining" here - //bail!("macaroon validate error: {:?}", e), return Err( - ErrorKind::InvalidCredentials("macaroon validate error".to_string()).into(), + ErrorKind::InvalidCredentials( + format!("macaroon validate error: {:?}", e)).into(), ); } }; @@ -267,7 +267,14 @@ impl AuthConfectionary { break; } } - let editor_id = editor_id.expect("expected an editor_id caveat"); + let editor_id = match editor_id { + Some(id) => id, + None => { + return Err( + ErrorKind::InvalidCredentials("expected an editor_id caveat".to_string()).into(), + ); + }, + }; verifier.satisfy_exact(&format!("editor_id = {}", editor_id.to_string())); if let Some(endpoint) = endpoint { // API endpoint @@ -284,7 +291,14 @@ impl AuthConfectionary { break; } } - let created = created.expect("expected a 'created' (time >) caveat"); + let created = match created { + Some(c) => c, + None => { + return Err( + ErrorKind::InvalidCredentials("expected a 'created' (time >) caveat".to_string()).into(), + ); + }, + }; verifier.satisfy_exact(&format!( "time > {}", created.to_rfc3339_opts(SecondsFormat::Secs, true) -- cgit v1.2.3