use axum::{ extract::{Path, State}, response::{self, IntoResponse}, }; use crate::{ error::Internal, invite, invite::app::Invites, ui::{ assets::{Asset, Assets}, error::NotFound, }, }; pub async fn handler( State(invites): State, Path(invite): Path, ) -> Result { invites .get(&invite) .await .map_err(Error::internal)? .ok_or(Error::NotFound)?; Assets::index().map_err(Error::Internal) } #[derive(Debug, thiserror::Error)] pub enum Error { #[error("invite not found")] NotFound, #[error("{0}")] Internal(Internal), } impl Error { fn internal(err: impl Into) -> Self { Self::Internal(err.into()) } } impl IntoResponse for Error { fn into_response(self) -> response::Response { match self { Self::NotFound => match Assets::index() { Ok(asset) => NotFound(asset).into_response(), Err(internal) => internal.into_response(), }, Self::Internal(error) => error.into_response(), } } }