From e06094f23ca861ea5ae4864d11fa8ce8b7d7aa2c Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Mon, 2 Feb 2026 13:05:49 +0200 Subject: feat: oauth route --- src/server/error/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/server/error/mod.rs (limited to 'src/server/error/mod.rs') diff --git a/src/server/error/mod.rs b/src/server/error/mod.rs new file mode 100644 index 0000000..6d07f9f --- /dev/null +++ b/src/server/error/mod.rs @@ -0,0 +1,27 @@ +use axum::{ + http::StatusCode, + response::{IntoResponse, Response}, +}; + +#[derive(Debug)] +pub struct AppError(anyhow::Error); + +// Tell axum how to convert `AppError` into a response. +impl IntoResponse for AppError { + fn into_response(self) -> Response { + tracing::error!("Application error: {:#}", self.0); + + (StatusCode::INTERNAL_SERVER_ERROR, "Something went wrong").into_response() + } +} + +// This enables using `?` on functions that return `Result<_, anyhow::Error>` to turn them into +// `Result<_, AppError>`. That way you don't need to do that manually. +impl From for AppError +where + E: Into, +{ + fn from(err: E) -> Self { + Self(err.into()) + } +} -- cgit v1.2.3