aboutsummaryrefslogtreecommitdiff
path: root/src/controller/error.rs
blob: 8dad16b3880f7bf03066d2e7f12c0d8edc172d1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()
}