use std::{io, path::PathBuf};
pub type ServerResult<T> = Result<T, ServerError>;
#[derive(Debug, thiserror::Error)]
pub enum ServerError {
#[error("TLS material load failed ({kind}) at `{path}`: {reason}")]
TlsLoad {
kind: TlsKind,
path: PathBuf,
reason: String,
},
#[error("invalid listener address `{addr}`: {reason}")]
ListenerAddress { addr: String, reason: String },
#[error("middleware script not found: `{path}`")]
MiddlewareMissing { path: PathBuf },
#[error("failed to compile middleware `{path}`: {reason}")]
MiddlewareCompile { path: PathBuf, reason: String },
#[error("i/o error: {0}")]
Io(#[from] io::Error),
#[error(transparent)]
Config(#[from] apimock_config::ConfigError),
}
#[derive(Debug, Clone, Copy)]
pub enum TlsKind {
Certificate,
PrivateKey,
}
impl std::fmt::Display for TlsKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TlsKind::Certificate => f.write_str("certificate"),
TlsKind::PrivateKey => f.write_str("private key"),
}
}
}