1use std::{io, path::PathBuf};
8
9pub type ServerResult<T> = Result<T, ServerError>;
10
11#[derive(Debug, thiserror::Error)]
12pub enum ServerError {
13 #[error("TLS material load failed ({kind}) at `{path}`: {reason}")]
15 TlsLoad {
16 kind: TlsKind,
17 path: PathBuf,
18 reason: String,
19 },
20
21 #[error("invalid listener address `{addr}`: {reason}")]
23 ListenerAddress { addr: String, reason: String },
24
25 #[error("middleware script not found: `{path}`")]
27 MiddlewareMissing { path: PathBuf },
28
29 #[error("failed to compile middleware `{path}`: {reason}")]
31 MiddlewareCompile { path: PathBuf, reason: String },
32
33 #[error("i/o error: {0}")]
35 Io(#[from] io::Error),
36
37 #[error(transparent)]
40 Config(#[from] apimock_config::ConfigError),
41}
42
43#[derive(Debug, Clone, Copy)]
44pub enum TlsKind {
45 Certificate,
46 PrivateKey,
47}
48
49impl std::fmt::Display for TlsKind {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 match self {
52 TlsKind::Certificate => f.write_str("certificate"),
53 TlsKind::PrivateKey => f.write_str("private key"),
54 }
55 }
56}