use std::error::Error as StdError;
use std::fmt;
use tokio_tungstenite::tungstenite::protocol::CloseFrame;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum Error {
BuildingUrl,
Closed(Option<CloseFrame<'static>>),
ExpectedHello,
HeartbeatFailed,
InvalidAuthentication,
InvalidHandshake,
InvalidShardData,
NoAuthentication,
NoSessionId,
OverloadedShard,
ReconnectFailure,
InvalidGatewayIntents,
DisallowedGatewayIntents,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::BuildingUrl => f.write_str("Error building url"),
Self::Closed(_) => f.write_str("Connection closed"),
Self::ExpectedHello => f.write_str("Expected a Hello"),
Self::HeartbeatFailed => f.write_str("Failed sending a heartbeat"),
Self::InvalidAuthentication => f.write_str("Sent invalid authentication"),
Self::InvalidHandshake => f.write_str("Expected a valid Handshake"),
Self::InvalidShardData => f.write_str("Sent invalid shard data"),
Self::NoAuthentication => f.write_str("Sent no authentication"),
Self::NoSessionId => f.write_str("No Session Id present when required"),
Self::OverloadedShard => f.write_str("Shard has too many guilds"),
Self::ReconnectFailure => f.write_str("Failed to Reconnect"),
Self::InvalidGatewayIntents => f.write_str("Invalid gateway intents were provided"),
Self::DisallowedGatewayIntents => {
f.write_str("Disallowed gateway intents were provided")
},
}
}
}
impl StdError for Error {}