use actix_web::{HttpResponse, ResponseError}; use std::fmt; /// Wraps any error so it can be returned with `?` from request handlers. /// Always surfaces as a 500 to the client; the real error is logged. pub struct AppError(anyhow::Error); impl fmt::Debug for AppError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.0, f) } } impl fmt::Display for AppError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.0, f) } } impl ResponseError for AppError { fn error_response(&self) -> HttpResponse { log::error!("Unhandled error: {:?}", self.0); HttpResponse::InternalServerError().finish() } } impl From for AppError where E: Into, { fn from(err: E) -> Self { AppError(err.into()) } }