Replace PlumeRocket.conn with DbConn
This commit is contained in:
+18
-10
@@ -1,5 +1,5 @@
|
||||
use crate::template_utils::{IntoContext, Ructe};
|
||||
use plume_models::{Error, PlumeRocket};
|
||||
use plume_models::{db_conn::DbConn, Error, PlumeRocket};
|
||||
use rocket::{
|
||||
response::{self, Responder},
|
||||
Request,
|
||||
@@ -17,40 +17,48 @@ impl From<Error> for ErrorPage {
|
||||
|
||||
impl<'r> Responder<'r> for ErrorPage {
|
||||
fn respond_to(self, req: &Request<'_>) -> response::Result<'r> {
|
||||
let conn = req.guard::<DbConn>().unwrap();
|
||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||
|
||||
match self.0 {
|
||||
Error::NotFound => render!(errors::not_found(&rockets.to_context())).respond_to(req),
|
||||
Error::Unauthorized => {
|
||||
render!(errors::not_found(&rockets.to_context())).respond_to(req)
|
||||
Error::NotFound => {
|
||||
render!(errors::not_found(&(&conn, &rockets).to_context())).respond_to(req)
|
||||
}
|
||||
_ => render!(errors::not_found(&rockets.to_context())).respond_to(req),
|
||||
Error::Unauthorized => {
|
||||
render!(errors::not_found(&(&conn, &rockets).to_context())).respond_to(req)
|
||||
}
|
||||
_ => render!(errors::not_found(&(&conn, &rockets).to_context())).respond_to(req),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
pub fn not_found(req: &Request<'_>) -> Ructe {
|
||||
let conn = req.guard::<DbConn>().unwrap();
|
||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||
render!(errors::not_found(&rockets.to_context()))
|
||||
render!(errors::not_found(&(&conn, &rockets).to_context()))
|
||||
}
|
||||
|
||||
#[catch(422)]
|
||||
pub fn unprocessable_entity(req: &Request<'_>) -> Ructe {
|
||||
let conn = req.guard::<DbConn>().unwrap();
|
||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||
render!(errors::unprocessable_entity(&rockets.to_context()))
|
||||
render!(errors::unprocessable_entity(
|
||||
&(&conn, &rockets).to_context()
|
||||
))
|
||||
}
|
||||
|
||||
#[catch(500)]
|
||||
pub fn server_error(req: &Request<'_>) -> Ructe {
|
||||
let conn = req.guard::<DbConn>().unwrap();
|
||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||
render!(errors::server_error(&rockets.to_context()))
|
||||
render!(errors::server_error(&(&conn, &rockets).to_context()))
|
||||
}
|
||||
|
||||
#[post("/csrf-violation?<target>")]
|
||||
pub fn csrf_violation(target: Option<String>, rockets: PlumeRocket) -> Ructe {
|
||||
pub fn csrf_violation(target: Option<String>, conn: DbConn, rockets: PlumeRocket) -> Ructe {
|
||||
if let Some(uri) = target {
|
||||
warn!("Csrf violation while accessing \"{}\"", uri)
|
||||
}
|
||||
render!(errors::csrf(&rockets.to_context()))
|
||||
render!(errors::csrf(&(&conn, &rockets).to_context()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user