mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-26 21:41:04 +00:00
Respond with error status code when error
This commit is contained in:
parent
7de37bc9b7
commit
e31a2238fb
1 changed files with 6 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
use crate::template_utils::{IntoContext, Ructe};
|
use crate::template_utils::{IntoContext, Ructe};
|
||||||
use plume_models::{db_conn::DbConn, Error, PlumeRocket};
|
use plume_models::{db_conn::DbConn, Error, PlumeRocket};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
|
http::Status,
|
||||||
response::{self, Responder},
|
response::{self, Responder},
|
||||||
Request,
|
Request,
|
||||||
};
|
};
|
||||||
|
@ -16,18 +17,13 @@ impl From<Error> for ErrorPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> Responder<'r> for ErrorPage {
|
impl<'r> Responder<'r> for ErrorPage {
|
||||||
fn respond_to(self, req: &Request<'_>) -> response::Result<'r> {
|
fn respond_to(self, _req: &Request<'_>) -> response::Result<'r> {
|
||||||
let conn = req.guard::<DbConn>().unwrap();
|
warn!("{:?}", self.0);
|
||||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
|
||||||
|
|
||||||
match self.0 {
|
match self.0 {
|
||||||
Error::NotFound => {
|
Error::NotFound => Err(Status::NotFound),
|
||||||
render!(errors::not_found(&(&conn, &rockets).to_context())).respond_to(req)
|
Error::Unauthorized => Err(Status::NotFound),
|
||||||
}
|
_ => Err(Status::InternalServerError),
|
||||||
Error::Unauthorized => {
|
|
||||||
render!(errors::not_found(&(&conn, &rockets).to_context())).respond_to(req)
|
|
||||||
}
|
|
||||||
_ => render!(errors::not_found(&(&conn, &rockets).to_context())).respond_to(req),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue