feat(poc): complete terrors PoC with main scenarios
This commit is contained in:
@@ -1,5 +1,26 @@
|
||||
mod errors;
|
||||
mod db;
|
||||
mod auth;
|
||||
mod db;
|
||||
mod errors;
|
||||
|
||||
fn main() {}
|
||||
use errors::ProtoError;
|
||||
|
||||
fn run(id: u32, sig: &str) {
|
||||
print!("authenticate(id={id}, sig={sig:?}) => ");
|
||||
match auth::authenticate(id, sig) {
|
||||
Ok(nonce) => println!("Ok(nonce={nonce})"),
|
||||
Err(e) => match e.narrow::<errors::NotRegistered, _>() {
|
||||
Ok(_) => println!("Err(NotRegistered) — handled locally"),
|
||||
Err(remaining) => {
|
||||
let proto = ProtoError::from(remaining);
|
||||
println!("Err(ProtoError::{proto:?}) — forwarded to wire");
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
run(0, "ok"); // NotRegistered
|
||||
run(1, "bad"); // InvalidSignature
|
||||
run(99, "ok"); // Internal
|
||||
run(1, "ok"); // success
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user