Something went wrong. Try again.
A small file server written in rust to share images/videos (aimed at discord)
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536use axum::{http::StatusCode, response::IntoResponse};
// Based off https://github.com/tokio-rs/axum/blob/main/examples/anyhow-error-response/src/main.rs;pub enum AppError { // Generic error from ? Err(anyhow::Error), // HandledErr(StatusCode, &'static str),}
// Let axum know how to turn our error into a responseimpl IntoResponse for AppError { fn into_response(self) -> axum::response::Response { match self { // AppError::Handled(status, text) => (status, text).into_response(), AppError::Err(anyhow) => ( StatusCode::INTERNAL_SERVER_ERROR, format!("Something went wrong! {}", anyhow), ) .into_response(),
AppError::HandledErr(code, text) => (code, text).into_response(), } }}
// Convert Result<_, anyhow::Error> into Result<_, AppError>impl<E> From<E> for AppErrorwhere E: Into<anyhow::Error>,{ fn from(err: E) -> Self { Self::Err(err.into()) }}