adk_surface/mobile/
error.rs1use adk_core::{AdkError, ErrorCategory, ErrorComponent};
4
5use crate::error::SurfaceError;
6
7#[derive(Debug, thiserror::Error)]
22pub enum MobileError {
23 #[error(
26 "the phone needs the home's public https URL: start adk-rust up with --home-url \
27 https://<host>"
28 )]
29 NeedsHomeUrl,
30 #[error(
33 "this push endpoint is refused: {reason}. A phone subscribes through its browser's push \
34 service (Apple, Google, Mozilla or Microsoft) over https"
35 )]
36 PushEndpoint {
37 reason: String,
39 },
40 #[error(
42 "the push key is unusable: {reason}. Delete the key file to create a new one; phones then \
43 allow notifications again"
44 )]
45 PushKey {
46 reason: String,
48 },
49 #[error(
51 "confirm it's you is not available on this server yet; approve high-risk calls on a \
52 paired local terminal"
53 )]
54 PasskeyUnavailable,
55 #[error(
57 "the passkey check failed: {reason}. Try again, or approve in the home on your computer"
58 )]
59 PasskeyRefused {
60 reason: String,
62 },
63 #[error(
65 "a phone sets up its passkey within 10 minutes of pairing: remove the phone and pair it \
66 again"
67 )]
68 RegistrationClosed,
69 #[error("this phone already has its passkey: remove the phone and pair it again to replace it")]
71 PasskeyExists,
72 #[error("{hint}")]
74 NoPasskey {
75 hint: &'static str,
77 },
78 #[error(
80 "this confirmation is used, expired or for another answer: tap the answer again to start \
81 a new one"
82 )]
83 Challenge,
84 #[error("a pairing QR code only holds a link into this home ({home})")]
86 QrUrl {
87 home: String,
89 },
90 #[error(transparent)]
92 Surface(#[from] SurfaceError),
93 #[error(transparent)]
95 Source(#[from] AdkError),
96}
97
98impl From<MobileError> for AdkError {
99 fn from(error: MobileError) -> Self {
100 let (category, code) = match &error {
101 MobileError::Surface(_) | MobileError::Source(_) => {
102 return match error {
103 MobileError::Surface(inner) => AdkError::from(inner),
104 MobileError::Source(inner) => inner,
105 _ => unreachable!("matched above"),
106 };
107 }
108 MobileError::NeedsHomeUrl => {
109 (ErrorCategory::InvalidInput, "surface.phone.needs_home_url")
110 }
111 MobileError::PushEndpoint { .. } => {
112 (ErrorCategory::InvalidInput, "surface.phone.push_endpoint")
113 }
114 MobileError::PushKey { .. } => (ErrorCategory::Internal, "surface.phone.push_key"),
115 MobileError::PasskeyUnavailable => {
116 (ErrorCategory::Unsupported, "surface.phone.passkey_unavailable")
117 }
118 MobileError::PasskeyRefused { .. } => {
119 (ErrorCategory::Forbidden, "surface.phone.passkey_refused")
120 }
121 MobileError::RegistrationClosed => {
122 (ErrorCategory::Forbidden, "surface.phone.registration_closed")
123 }
124 MobileError::PasskeyExists => (ErrorCategory::Conflict, "surface.phone.passkey_exists"),
125 MobileError::NoPasskey { .. } => (ErrorCategory::Forbidden, "surface.phone.no_passkey"),
126 MobileError::Challenge => (ErrorCategory::Forbidden, "surface.phone.challenge"),
127 MobileError::QrUrl { .. } => (ErrorCategory::InvalidInput, "surface.phone.qr_url"),
128 };
129 AdkError::new(ErrorComponent::Server, category, code, error.to_string())
130 }
131}