Can I implement actix_web::ResponseError
trait for rustis::Error
?
#52
Replies: 2 comments 4 replies
-
Hi @bioinformatist, In my opinion, the best way to handle errors in web frameworks is to define your own error enum. It would not be scalable to ask every library to implement the error traits defined by all existing frameworks. This is a solution I use for my own rest apis: You can then implement the trait actix_web::ResponseError on your custom error and implement From<rustis::Error> manually or with the help of the crate thiserror #[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Rustis Error: {0}")]
Rustis(#[from] rustis::Error),
// Add other nested errors here
}
implement actix_web::ResponseError for Error {
// Implement the trait here
} You can then declare routes with functions returning your custom error and you use the idiomatic error ? operator to return rustis errors which will be automatically converted to your custom error. Please let me know if this solution is suitable for you and will close this issue. PS: thank you for the good words about rustis <3 |
Beta Was this translation helpful? Give feedback.
-
By the way, you can fine a complete example here: In this example, |
Beta Was this translation helpful? Give feedback.
-
@mcatanzariti Hi Michaël, we're developing web apps with
actix-web
andrustis
. In order to useResult<impl Responder, E>
as the return value of actix-web's handlers, theactix_web::ResponseError
trait needs to be implemented forrustis::Error
. I thinkrustis
is the best Redis client (with well-designed architecture and easy-to-use APIs), and given that Redis will be utilized by numerous applications, I believe this implementation will greatly benefit many developers (and also attract new users for us). May I submit a PR for this?Beta Was this translation helpful? Give feedback.
All reactions