use std::{error::Error as StdError, fmt};
#[derive(Debug)]
#[non_exhaustive]
pub enum TestkitError {
RequestBuild(axum::http::Error),
ResponseBody(axum::Error),
ResponseUtf8(std::string::FromUtf8Error),
ResponseJson(serde_json::Error),
}
impl fmt::Display for TestkitError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::RequestBuild(source) => write!(formatter, "test request build failed: {source}"),
Self::ResponseBody(source) => write!(formatter, "response body read failed: {source}"),
Self::ResponseUtf8(source) => write!(formatter, "response body is not UTF-8: {source}"),
Self::ResponseJson(source) => write!(formatter, "response body is not JSON: {source}"),
}
}
}
impl StdError for TestkitError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
Self::RequestBuild(source) => Some(source),
Self::ResponseBody(source) => Some(source),
Self::ResponseUtf8(source) => Some(source),
Self::ResponseJson(source) => Some(source),
}
}
}