use crate::responses::StatusCode;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("failed constructing a valid URI")]
InvalidUri(#[from] InvalidUriError),
#[error("failed to connect to the obs-websocket plugin")]
Connect(#[from] ConnectError),
#[error("timeout happened before the connection could be established")]
Timeout,
#[error("failed to execute the handshake with obs-websocket")]
Handshake(#[from] crate::client::HandshakeError),
#[error("failed to serialize message")]
SerializeMessage(#[from] SerializeMessageError),
#[error("failed to send message to the obs-websocket plugin")]
Send(#[from] SendError),
#[error("send side is closed")]
ReceiveMessage(#[from] ReceiveMessageError),
#[error("the response message could not be deserialized")]
DeserializeResponse(#[from] DeserializeResponseError),
#[error("failed to serialize custom data")]
SerializeCustomData(#[from] SerializeCustomDataError),
#[error("custom data must serialize into a JSON object")]
InvalidCustomData,
#[error("API error: {code:?}")]
Api {
code: StatusCode,
message: Option<String>,
},
#[error("value {0} contains unknown flags")]
UnknownFlags(u8),
#[error("currently not connected to obs-websocket")]
Disconnected,
#[error("obs studio version {0} doesn't match required {1}")]
ObsStudioVersion(semver::Version, semver::Comparator),
#[error("obs-websocket version {0} doesn't match required {1}")]
ObsWebsocketVersion(semver::Version, semver::Comparator),
#[error("RPC version {requested} requested, but server negotiated version {negotiated}")]
RpcVersion {
requested: u32,
negotiated: u32,
},
}
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct InvalidUriError(pub(crate) http::uri::InvalidUri);
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct ConnectError(pub(crate) tokio_websockets::Error);
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct SerializeMessageError(pub(crate) serde_json::Error);
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct SendError(pub(crate) tokio_websockets::Error);
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct ReceiveMessageError(pub(crate) tokio::sync::oneshot::error::RecvError);
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct DeserializeResponseError(pub(crate) serde_json::Error);
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct SerializeCustomDataError(pub(crate) serde_json::Error);