Compiler won't recognize that I'm implementing rocket::response::Responder

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)

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 {
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().

You haven't stated which code triggers the error, but you don't appear to have functions returning an AuthError in the code you linked. You are instead returning a Result with an error type of Box<dyn Error>. Since that isn't guaranteed to implement Responder, it seems it is using the deprecated fallback implementation for Results with a non-Responder error type, rather than the implementation for error types implenting Error and Responder. Using AuthError directly as the error type should give the behaviour you expect.

Hmm... the reason I return Box<dyn Error> is because the functions below can error for any kind of reason - it could return a io::Error or my custom CommandError, or AuthError. What should I return then?

I would suggest you want a custom error type, either an enum with variants for each error type you might generate and a From implementation to convert each to the custom type, or a trait combining Responder and Error that you can make a trait object of. The first approach gives you a lot of control but is a lot of work. The second approach requires you to make sure every error returned implements Responder, but that should just be a case of wrapping things that don't implement it in rocket::response::Debug.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.