use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub enum MswError {
AlreadyStarted,
NotStarted,
Bind(std::io::Error),
NativePassthroughUnsupported,
Shutdown(String),
}
impl fmt::Display for MswError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::AlreadyStarted => write!(f, "MockServiceWorker is already started"),
Self::NotStarted => write!(f, "MockServiceWorker is not started"),
Self::Bind(err) => write!(f, "failed to bind native MSW listener: {err}"),
Self::NativePassthroughUnsupported => write!(
f,
"UnhandledPolicy::Passthrough is not supported on native MSW"
),
Self::Shutdown(message) => write!(f, "native MSW shutdown failed: {message}"),
}
}
}
impl Error for MswError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Bind(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for MswError {
fn from(err: std::io::Error) -> Self {
Self::Bind(err)
}
}