Handle more errors

This commit is contained in:
Vecna 2024-06-06 17:14:06 -04:00
parent 4eb3204240
commit 2e94b4df34
1 changed files with 14 additions and 2 deletions

View File

@ -8,6 +8,7 @@ use lox_library::{
scalar_u32, IssuerPubKey, OPENINV_LENGTH,
};
use lox_utils::{EncBridgeTable, Invite};
use serde::de::Error as SerdeError;
use serde_json::error::Error;
use std::collections::HashMap;
@ -115,7 +116,10 @@ pub async fn get_bucket(
let (id, key) = from_scalar(lox_cred.bucket).unwrap();
let encbucket = match encbuckets.get(&id) {
Some(encbucket) => encbucket,
None => panic!("Provided ID not found"),
None => {
// This is probably an abuse of the serde_json Error struct.
return Err(Error::missing_field("Provided ID not found"));
}
};
Ok(BridgeTable::decrypt_bucket(id, &key, &encbucket).unwrap())
}
@ -210,7 +214,15 @@ pub async fn issue_invite(
let (id, key) = from_scalar(lox_cred.bucket).unwrap();
let bucket = BridgeTable::decrypt_bucket(id, &key, &encbuckets.get(&id).unwrap()).unwrap();
let reachcred = bucket.1.unwrap();
let reachcred = match bucket.1 {
Some(v) => v,
None => {
// This is probably an abuse of the serde_json Error struct.
return Err(Error::missing_field(
"Expected reachability credential but none was found",
));
}
};
let (req, state) = issue_invite::request(
lox_cred,