aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-08 15:37:47 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-08 15:37:47 -0800
commite2cd8b331c7558688b0ec5b807a76ca104f40f84 (patch)
treeb8d375afee09c1f5e278c78e74384c9a4a9c785e /rust
parentb44fd9a78c1505258178a51201e8abea9977baa5 (diff)
downloadfatcat-e2cd8b331c7558688b0ec5b807a76ca104f40f84.tar.gz
fatcat-e2cd8b331c7558688b0ec5b807a76ca104f40f84.zip
better rust auth error handling/responses
Diffstat (limited to 'rust')
-rw-r--r--rust/src/auth.rs30
1 files changed, 22 insertions, 8 deletions
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)