#[derive(Debug)]
pub enum Error {
NoWindow,
NoDocument,
NoLiveSocket,
NoLiveViewRoot,
Serialize(String),
ExecFailed(String),
}
impl From<serde_json::Error> for Error {
fn from(error: serde_json::Error) -> Self {
Error::Serialize(error.to_string())
}
}
impl core::fmt::Display for Error {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::NoWindow => write!(formatter, "no browser window"),
Error::NoDocument => write!(formatter, "no document on window"),
Error::NoLiveSocket => write!(formatter, "window.liveSocket not initialized"),
Error::NoLiveViewRoot => write!(formatter, "no [data-phx-session] element found"),
Error::Serialize(message) => {
write!(formatter, "could not serialize payload: {message}")
}
Error::ExecFailed(message) => {
write!(formatter, "liveSocket.execJS threw: {message}")
}
}
}
}
impl std::error::Error for Error {}