aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2024-01-30 16:48:26 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2024-01-30 16:48:26 +0000
commit849a348503ca38c171276f658f1ac4bd273ef2d1 (patch)
tree6c07cea0fe2d6e06d4ce24f0d76d630a74ca815e /src/main.rs
parentf00159f53b3774601500ec65345791311ff6efa1 (diff)
downloadblossom-849a348503ca38c171276f658f1ac4bd273ef2d1.tar.gz
blossom-849a348503ca38c171276f658f1ac4bd273ef2d1.tar.bz2
blossom-849a348503ca38c171276f658f1ac4bd273ef2d1.zip
catch all errors to custom template
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index c38b2eb..25bc21f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,7 +12,6 @@ use std::rc::Rc;
use std::{collections::HashSet, time::Duration};
use poem::http::StatusCode;
-use poem::Response;
use poem::{
endpoint::EmbeddedFilesEndpoint,
get, handler,
@@ -21,6 +20,7 @@ use poem::{
web::{Data, Path, Query},
EndpointExt, Route, Server,
};
+use poem::{IntoResponse, Response};
use rust_embed::RustEmbed;
use error::BlossomError;
@@ -114,6 +114,14 @@ async fn plants() -> Result<()> {
Err(BlossomError::Unimplemented)
}
+async fn custom_error(err: poem::Error) -> impl IntoResponse {
+ templates::Error {
+ status: err.status(),
+ message: err.to_string(),
+ }
+ .with_status(err.status())
+}
+
#[tokio::main]
async fn main() -> std::result::Result<(), std::io::Error> {
// let mut skinny_data = mastodon_async::Data::default();
@@ -126,6 +134,7 @@ async fn main() -> std::result::Result<(), std::io::Error> {
.at("/contact", get(contact))
.at("/plants", get(plants))
.nest("/static/", EmbeddedFilesEndpoint::<Static>::new())
+ .catch_all_error(custom_error)
.with(AddData::new(
reqwest::Client::builder()
.connect_timeout(Duration::from_secs(1))