Respond with error status code when error

This commit is contained in:
Kitaiti Makoto 2022-01-12 08:58:42 +09:00
parent 7de37bc9b7
commit e31a2238fb

View File

@ -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),
} }
} }
} }