use thiserror::Error;
#[derive(Debug, Error)]
pub enum ProxyError {
#[error("config: {0}")]
Config(String),
#[error("no route for {0}")]
NoRoute(String),
#[error("no upstream in cluster '{0}'")]
NoUpstream(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display() {
let e = ProxyError::Config("bad yaml".into());
assert_eq!(e.to_string(), "config: bad yaml", "Config error display mismatch");
let e = ProxyError::NoRoute("GET /missing".into());
assert_eq!(
e.to_string(),
"no route for GET /missing",
"NoRoute error display mismatch"
);
let e = ProxyError::NoUpstream("backend".into());
assert_eq!(
e.to_string(),
"no upstream in cluster 'backend'",
"NoUpstream error display mismatch"
);
}
}