static template context for errors
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cae6b0c97f
commit
a0853ed3de
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1455,6 +1455,7 @@ name = "qchgk_web"
|
|||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chgk_ledb_lib",
|
"chgk_ledb_lib",
|
||||||
|
"lazy_static",
|
||||||
"mini-moka",
|
"mini-moka",
|
||||||
"rand",
|
"rand",
|
||||||
"rocket",
|
"rocket",
|
||||||
|
@ -15,6 +15,7 @@ rocket = { version = "=0.5.0-rc.3", features = ["json"] }
|
|||||||
rocket_dyn_templates = { version = "=0.1.0-rc.3", features = ["tera"] }
|
rocket_dyn_templates = { version = "=0.1.0-rc.3", features = ["tera"] }
|
||||||
chgk_ledb_lib = {git = "https://gitea.b4tman.ru/b4tman/chgk_ledb.git", rev="699478f85e", package="chgk_ledb_lib", features=["async"]}
|
chgk_ledb_lib = {git = "https://gitea.b4tman.ru/b4tman/chgk_ledb.git", rev="699478f85e", package="chgk_ledb_lib", features=["async"]}
|
||||||
mini-moka = "0.10.0"
|
mini-moka = "0.10.0"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
11
src/main.rs
11
src/main.rs
@ -14,6 +14,7 @@ use rocket_dyn_templates::Template;
|
|||||||
use rand::distributions::Uniform;
|
use rand::distributions::Uniform;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -26,6 +27,10 @@ use std::time::Duration;
|
|||||||
|
|
||||||
const DB_FILENAME: &str = "db.dat";
|
const DB_FILENAME: &str = "db.dat";
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref EMPTY_MAP: HashMap<String, String> = HashMap::new();
|
||||||
|
}
|
||||||
|
|
||||||
trait ErrorEmpty {
|
trait ErrorEmpty {
|
||||||
type Output;
|
type Output;
|
||||||
fn err_empty(self) -> Result<Self::Output, ()>;
|
fn err_empty(self) -> Result<Self::Output, ()>;
|
||||||
@ -48,12 +53,10 @@ enum WebError {
|
|||||||
|
|
||||||
impl WebError {
|
impl WebError {
|
||||||
fn not_found() -> Self {
|
fn not_found() -> Self {
|
||||||
let context: HashMap<String, String> = HashMap::new();
|
WebError::NotFound(Template::render("404", EMPTY_MAP.deref()))
|
||||||
WebError::NotFound(Template::render("404", context))
|
|
||||||
}
|
}
|
||||||
fn server_error() -> Self {
|
fn server_error() -> Self {
|
||||||
let context: HashMap<String, String> = HashMap::new();
|
WebError::ServerError(Template::render("500", EMPTY_MAP.deref()))
|
||||||
WebError::ServerError(Template::render("500", context))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user