Rocket 0.4.5 was complaining that my response struct did not implement the 'Responder' trait:
=> Matched: POST /send/<to_address>/<amount> (http_send)
Form(SendAuth { token: "linuxize" })
=> Error: Response was a non-`Responder` `Err`: AuthError { details: "Your token was wrong" }.
=> Warning: This `Responder` implementation has been deprecated.
=> Warning: In Rocket v0.5, `Result<T, E>` implements `Responder` only if `E` implements `Responder`. For the previous behavior, use `Result<T, Debug<E>>` where `Debug` is `rocket::response::Debug`.
=> Outcome: Failure
=> Warning: Responding with 500 Internal Server Error catcher.
=> Response succeeded.
But I did implement it here (github repo)
#[derive(Debug)]
struct AuthError {
details: String,
}
impl AuthError {
fn new(msg: &str) -> AuthError {
AuthError {
details: msg.to_string(),
}
}
}
impl fmt::Display for AuthError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.details)
}
}
impl error::Error for AuthError {
fn description(&self) -> &str {
&self.details
}
}
impl<'r> Responder<'r> for AuthError {
fn respond_to(self, _: &rocket::Request) ->rocket::response::Result<'r> {
Err(rocket::http::Status::new(401, "BAD TOKEN"))
}
}
Overall I'm unsure as what to return from respond_to()
. Since it's an AuthError struct, there's no reason to respond with an Ok()
.