Skip to content

Responder for a foreign T: Error #1824

Answered by 3olkin
s0lst1ce asked this question in Questions
Discussion options

You must be logged in to vote

You can create another Error struct or enum or just type and impl From<AdapterError> for Error. This way you could use almost the same code as in your example, but you have to change from Result<(), AdapterError> to Result<(), Error

Small example:

use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
    #[error("jwt error: {0}")]
    JwtError(#[from] jsonwebtoken::errors::Error),
    #[error("diesel query error: {0}")]
    DieselQueryError(#[from] diesel::result::Error),
    #[error("wrong credentials")]
    WrongCredentials,
}

impl From<Error> for api::Error {
    fn from(err: Error) -> Self {
        let (status, reason) = match err {
            _ => (Status::InternalServer…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@s0lst1ce
Comment options

@3olkin
Comment options

@s0lst1ce
Comment options

Answer selected by s0lst1ce
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants