diff options
Diffstat (limited to 'src/controller/error.rs')
-rw-r--r-- | src/controller/error.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/controller/error.rs b/src/controller/error.rs new file mode 100644 index 0000000..8dad16b --- /dev/null +++ b/src/controller/error.rs @@ -0,0 +1,31 @@ +use hyper::header::CACHE_CONTROL; +use hyper::{Body, Response}; +use std::collections::HashMap; +use tera::{Context, Tera}; + +use crate::controller::utils; +use crate::controller::wallet::Wallet; + +pub fn error(wallet: &Wallet, title: &str, message: &str) -> Response<Body> { + utils::with_header( + Response::new( + template(&wallet.assets, &wallet.templates, title, message).into(), + ), + CACHE_CONTROL, + "no-cache", + ) +} + +pub fn template( + assets: &HashMap<String, String>, + templates: &Tera, + title: &str, + message: &str, +) -> String { + let mut context = Context::new(); + context.insert("title", title); + context.insert("message", message); + context.insert("assets", assets); + + templates.render("error.html", &context).unwrap() +} |