-
Hey everyone 👋 I posed this question in the IRC but was unable to stick around to see if it was answered: I may be misunderstanding, but if a guard returns a Here's an example: #[macro_use] extern crate rocket;
use rocket::{fs::NamedFile, http::Status, request::FromRequest, request::Outcome, response::status::NotFound};
#[get("/")]
async fn index(_guard: MyGuard) -> Result<NamedFile, NotFound<String>> {
NamedFile::open("templates/index.html")
.await
.map_err(|e| NotFound(e.to_string()))
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![index])
.register("/", catchers![catch_401])
}
#[catch(401)]
fn catch_401() -> &'static str {
"ACCESS DENIED"
}
#[derive(Debug)]
enum MyError {
ChromeError(&'static str),
}
struct MyGuard;
#[rocket::async_trait]
impl<'r> FromRequest<'r> for MyGuard {
type Error = MyError;
async fn from_request(request: &'r rocket::Request<'_>) -> Outcome<Self, Self::Error> {
let user_agent = String::from(request.headers().get_one("User-Agent").unwrap());
if user_agent.contains("Chrome") {
return Outcome::Failure((Status::Unauthorized, MyError::ChromeError("ACCESS DENIED")));
}
Outcome::Success(Self)
}
} The docs make no mention of whether #[catch(401)]
fn catch_401() -> &'static str {
"ACCESS DENIED"
// can I log MyError here?
} can use
Maybe it's not a good idea that the catcher should have access to that error content? Or is it that the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a desired feature (see #749), which unfortunately required or seemed to require new features in the rust language. |
Beta Was this translation helpful? Give feedback.
This is a desired feature (see #749), which unfortunately required or seemed to require new features in the rust language.