sipx_ua/error.rs
1//! User agent errors.
2
3use thiserror::Error;
4
5/// What can go wrong in the user agent.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum Error {
9 /// The transport failed.
10 #[error("transport: {0}")]
11 Transport(#[from] sipx_transport::Error),
12 /// A message could not be built.
13 #[error("build: {0}")]
14 Build(#[from] sipx_sip::error::BuildError),
15 /// The transaction ended without a final response — a timeout or a transport failure.
16 #[error("no final response")]
17 NoResponse,
18 /// The server challenged and no credentials were configured.
19 #[error("the server requires credentials and none were configured")]
20 CredentialsRequired,
21 /// The server challenged again after credentials were supplied, and did not say the nonce
22 /// was stale. Retrying would be guessing at a password.
23 #[error("authentication failed")]
24 AuthenticationFailed,
25 /// The flow's reflexive address changed, so the flow has failed (RFC 5626 §4.4.2).
26 ///
27 /// Not a transport error: the socket works. The NAT rebound, so the mapping the registrar
28 /// holds for this flow no longer reaches it, and §4.4.2 requires the UA to treat that as a
29 /// failure and re-establish rather than carry on pinging an address nothing routes to.
30 #[error("the flow's reflexive address changed from {previous} to {current}")]
31 FlowRebound {
32 /// The address the previous keep-alive reported.
33 previous: std::net::SocketAddr,
34 /// The address this one did.
35 current: std::net::SocketAddr,
36 },
37 /// More flows were added than `reg-id` can number (RFC 5626 §4.2 caps it at 2^31 - 1).
38 #[error("too many flows: reg-id cannot number more than 2^31 - 1 of them")]
39 TooManyFlows,
40 /// The registrar answered 555: it does not support the push notification service the
41 /// `Contact` named (RFC 8599 §8.1).
42 ///
43 /// Distinct from [`Error::Rejected`] because retrying cannot help. Every attempt naming this
44 /// push service will be refused the same way, and a client that treats it as a transient
45 /// failure stays unreachable while looking busy.
46 #[error("the registrar does not support the push notification service named: 555 {reason}")]
47 PushNotSupported {
48 /// The reason phrase the registrar sent.
49 reason: String,
50 },
51 /// The server refused.
52 #[error("rejected: {status} {reason}")]
53 Rejected {
54 /// The status code.
55 status: u16,
56 /// Its reason phrase.
57 reason: String,
58 },
59}
60
61/// A user agent result.
62pub type Result<T> = std::result::Result<T, Error>;