soap_client/error.rs
1//! Error types for the SOAP client
2
3use thiserror::Error;
4
5/// Errors that can occur during SOAP communication
6#[derive(Debug, Error)]
7pub enum SoapError {
8 /// Network or HTTP communication error
9 #[error("Network/HTTP error: {0}")]
10 Network(String),
11
12 /// XML parsing error
13 #[error("XML parsing error: {0}")]
14 Parse(String),
15
16 /// SOAP fault returned by the device
17 ///
18 /// UPnP devices report action failures as an HTTP 500 response whose body is
19 /// a `<s:Fault>` envelope. The `code` is the standardized UPnP error code
20 /// (e.g. 402 = Invalid Args, 701 = Transition Not Available) and
21 /// `description` is the device's human-readable reason, when it supplies one.
22 #[error("SOAP fault: error code {code}{}", .description.as_deref().map(|d| format!(" ({d})")).unwrap_or_default())]
23 Fault {
24 /// UPnP error code from `<errorCode>`
25 code: u16,
26 /// Device-supplied reason from `<errorDescription>`, if present
27 description: Option<String>,
28 },
29}
30
31impl SoapError {
32 /// Construct a fault with no device-supplied description.
33 ///
34 /// Convenience for tests and for callers that only have a code.
35 pub fn fault(code: u16) -> Self {
36 Self::Fault {
37 code,
38 description: None,
39 }
40 }
41}