use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use figment::Error as FigmentError;
use glob::PatternError;
use std::{
io::Error as IoError,
path::PathBuf,
};
use thiserror::Error as ThisError;
#[cfg(feature = "auth")]
use crate::auth::errors::AuthError;
#[cfg(feature = "tera")]
use tera::Error as TemplateError;
#[derive(Debug, ThisError)]
#[non_exhaustive]
pub enum AppError {
#[cfg(feature = "auth")]
#[error("Authentication error: {0}")]
AuthError(#[from] AuthError),
#[error("Configuration error: {0}")]
ConfigError(#[from] FigmentError),
#[error("Could not bind to host and port: {0}")]
CouldNotBind(#[from] IoError),
#[error("Could not start server: {0}")]
CouldNotStartServer(IoError),
#[cfg(feature = "tera")]
#[error("Could not add template {0}: {1}")]
CouldNotAddTemplate(PathBuf, TemplateError),
#[cfg(feature = "tera")]
#[error("Could not load template {0}: {1}")]
CouldNotLoadTemplate(PathBuf, IoError),
#[error("Glob pattern error: {0}")]
GlobError(#[from] PatternError),
#[error("Invalid template encoding: {0}")]
InvalidTemplateEncoding(PathBuf),
#[error("Invalid template path: {0}")]
InvalidTemplatePath(PathBuf),
#[cfg(feature = "tera")]
#[error("Template error: {0}")]
TemplateError(#[from] TemplateError),
#[cfg(feature = "tera")]
#[error("Template file not found: {0}")]
TemplateFileNotFound(PathBuf),
}
impl IntoResponse for AppError {
fn into_response(self) -> Response {
(
StatusCode::INTERNAL_SERVER_ERROR,
self.to_string(),
).into_response()
}
}