error_chain! {
errors {
AVTransportError(error: AVTransportError) {
description("An error occurred from AVTransport")
display("Received error {:?} from Sonos speaker", error)
}
ParseError {
description("An error occurred when attempting to parse SOAP XML from Sonos")
display("Failed to parse Sonos response XML")
}
DeviceUnreachable {
description("An error occurred when attempting to contact the device")
display("Failed to call Sonos endpoint")
}
BadResponse {
description("The device returned a bad response")
display("Received a non-success response from Sonos")
}
DeviceNotFound(identifier: String) {
description("An error occurred when trying to find device")
display("Couldn't find a device by the given identifier ({})", identifier)
}
}
}
impl From<AVTransportError> for ErrorKind {
fn from(error: AVTransportError) -> Self {
ErrorKind::AVTransportError(error)
}
}
#[derive(Debug)]
pub enum AVTransportError {
InvalidAction = 401,
InvalidArgs = 402,
InvalidVar = 404,
ActionFailed = 501,
TransitionNotAvailable = 701,
NoContents = 702,
ReadError = 703,
FormatNotSupported = 704,
TransportLocked = 705,
WriteError = 706,
MediaNotWriteable = 707,
RecordingFormatNotSupported = 708,
MediaFull = 709,
SeekModeNotSupported = 710,
IllegalSeekTarget = 711,
PlayModeNotSupported = 712,
RecordQualityNotSupported = 713,
IllegalMimeType = 714,
ContentBusy = 715,
PlaySpeedNotSupported = 717,
InvalidInstanceId = 718,
NoDnsServer = 737,
BadDomainName = 738,
ServerError = 739,
Unknown,
}
impl From<u64> for AVTransportError {
fn from(code: u64) -> AVTransportError {
match code {
401 => AVTransportError::InvalidAction,
402 => AVTransportError::InvalidArgs,
404 => AVTransportError::InvalidVar,
501 => AVTransportError::ActionFailed,
701 => AVTransportError::TransitionNotAvailable,
702 => AVTransportError::NoContents,
703 => AVTransportError::ReadError,
704 => AVTransportError::FormatNotSupported,
705 => AVTransportError::TransportLocked,
706 => AVTransportError::WriteError,
707 => AVTransportError::MediaNotWriteable,
708 => AVTransportError::RecordingFormatNotSupported,
709 => AVTransportError::MediaFull,
710 => AVTransportError::SeekModeNotSupported,
711 => AVTransportError::IllegalSeekTarget,
712 => AVTransportError::PlayModeNotSupported,
713 => AVTransportError::RecordQualityNotSupported,
714 => AVTransportError::IllegalMimeType,
715 => AVTransportError::ContentBusy,
717 => AVTransportError::PlaySpeedNotSupported,
718 => AVTransportError::InvalidInstanceId,
737 => AVTransportError::NoDnsServer,
738 => AVTransportError::BadDomainName,
739 => AVTransportError::ServerError,
_ => AVTransportError::Unknown,
}
}
}