summaryrefslogtreecommitdiff
path: root/src/index/routes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/index/routes.rs')
-rw-r--r--src/index/routes.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/index/routes.rs b/src/index/routes.rs
index 32c7f12..37f6dc9 100644
--- a/src/index/routes.rs
+++ b/src/index/routes.rs
@@ -1,13 +1,13 @@
use axum::{
extract::{Path, State},
http::{header, StatusCode},
- response::IntoResponse,
+ response::{IntoResponse, Response},
routing::get,
Router,
};
use maud::Markup;
-use super::templates;
+use super::{app, templates};
use crate::{
app::App,
error::InternalError,
@@ -49,11 +49,31 @@ async fn channel(
State(app): State<App>,
_: Login,
Path(channel): Path<channel::Id>,
-) -> Result<Markup, InternalError> {
- let channel = app.index().channel(&channel).await?;
+) -> Result<Markup, ChannelError> {
+ let channel = app
+ .index()
+ .channel(&channel)
+ .await
+ // impl From would work here, but it'd take more code.
+ .map_err(ChannelError)?;
Ok(templates::channel(&channel))
}
+#[derive(Debug)]
+struct ChannelError(app::Error);
+
+impl IntoResponse for ChannelError {
+ fn into_response(self) -> Response {
+ let Self(error) = self;
+ match error {
+ not_found @ app::Error::ChannelNotFound(_) => {
+ (StatusCode::NOT_FOUND, not_found.to_string()).into_response()
+ }
+ app::Error::DatabaseError(error) => InternalError::from(error).into_response(),
+ }
+ }
+}
+
pub fn router() -> Router<App> {
Router::new()
.route("/", get(index))