use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum SoapError {
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("HTTP {code}: {reason}")]
HttpStatus {
code: u16,
reason: String,
},
#[error("failed to serialize request: {0}")]
SerializeRequest(#[source] quick_xml::se::SeError),
#[error("failed to deserialize response: {0}")]
DeserializeResponse(#[source] Box<quick_xml::de::DeError>),
#[error("soap fault: [{code}] {message}")]
SoapFault {
code: String,
message: String,
},
#[error("operation '{name}' not found in WSDL definition")]
OperationNotFound {
name: String,
},
#[error("no endpoint URL configured for Soap client")]
NoEndpoint,
#[error("failed to load client certificate")]
CertLoad(#[source] CertError),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CertError {
#[error("read certificate file {path}")]
ReadCertFile {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("parse PEM bundle")]
ParsePem(#[source] reqwest::Error),
#[error("build HTTP client with identity")]
BuildClient(#[source] reqwest::Error),
}
impl SoapError {
pub fn http_status(status: reqwest::StatusCode) -> Self {
Self::HttpStatus {
code: status.as_u16(),
reason: status.canonical_reason().unwrap_or("Unknown").to_string(),
}
}
pub fn serialize_request(err: quick_xml::se::SeError) -> Self {
Self::SerializeRequest(err)
}
}