pub fn customize_error(err: Rejection) -> Result<impl Reply, Rejection> {
    let mut resp = err.json();
    if err.is_not_found() {
        *resp.status_mut() = StatusCode::NOT_FOUND;
        return Ok(resp)
    }

    let cause = match err.find_cause::<crate::error::Error>() {
        Some(ok) => ok,
        None => return Ok(resp)
    };
    match *cause {
        Error::DatabaseUnavailable => *resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
        Error::DatabaseError(_) => *resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
        Error::IllegalToken => *resp.status_mut() = StatusCode::UNAUTHORIZED,
        Error::ExpiredToken => *resp.status_mut() = StatusCode::UNAUTHORIZED,
        Error::MalformedToken => *resp.status_mut() = StatusCode::UNAUTHORIZED,
        Error::NotAuthorized => *resp.status_mut() = StatusCode::FORBIDDEN,
        Error::UserBanned => *resp.status_mut() = StatusCode::FORBIDDEN,
        Error::BadRequest => *resp.status_mut() = StatusCode::BAD_REQUEST,
        Error::NotFound => *resp.status_mut() = StatusCode::NOT_FOUND,
        Error::InternalServerError => *resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
    }

    warn!("rewrote error response: {:?}", resp);
    Ok(resp)
}
/// Takes a rejection, which Warp would otherwise handle in its own way, and transform it into
/// an Ok(Reply) where the status is set to correspond to the provided error.
///
/// This only works if the Rejection is of the custom Error type. Any others will just fall through this unchanged.
///
/// This should be used at the top level of the exposed api.
Takes a rejection, which Warp would otherwise handle in its own way, and transform it into
an Ok(Reply) where the status is set to correspond to the provided error.

This only works if the Rejection is of the custom Error type. Any others will just fall through this unchanged.

This should be used at the top level of the exposed api.
Takes a rejection which Warp would otherwise handle in its own way and transform it into an Ok ( Reply ) where the status is set to correspond to the provided error . This only works if the Rejection is of the custom Error type . Any others will just fall through this unchanged . This should be used at the top level of the exposed api .
pub fn customize_error(err: Rejection) -> Result<impl Reply, Rejection> {
    let mut resp = err.json();
    if err.is_not_found() {
        *resp.status_mut() = StatusCode::NOT_FOUND;
        return Ok(resp)
    }
    let cause = match err.find_cause::<crate::error::Error>() {
        Some(ok) => ok,
        None => return Ok(resp)
    };
    match *cause {
        Error::DatabaseUnavailable => *resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
        Error::DatabaseError(_) => *resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
        Error::IllegalToken => *resp.status_mut() = StatusCode::UNAUTHORIZED,
        Error::ExpiredToken => *resp.status_mut() = StatusCode::UNAUTHORIZED,
        Error::MalformedToken => *resp.status_mut() = StatusCode::UNAUTHORIZED,
        Error::NotAuthorized => *resp.status_mut() = StatusCode::FORBIDDEN,
        Error::UserBanned => *resp.status_mut() = StatusCode::FORBIDDEN,
        Error::BadRequest => *resp.status_mut() = StatusCode::BAD_REQUEST,
        Error::NotFound => *resp.status_mut() = StatusCode::NOT_FOUND,
        Error::InternalServerError => *resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
    }
    warn!("rewrote error response: {:?}", resp);
    Ok(resp)
}
pub fn customize_error ( err : Rejection ) -> Result < impl Reply , Rejection > { let mut resp = err . json ( ) ; if err . is_not_found ( ) { * resp . status_mut ( ) = StatusCode :: NOT_FOUND ; return Ok ( resp ) } let cause = match err . find_cause :: < crate :: error :: Error > ( ) { Some ( ok ) => ok , None => return Ok ( resp ) } ; match * cause { Error :: DatabaseUnavailable => * resp . status_mut ( ) = StatusCode :: INTERNAL_SERVER_ERROR , Error :: DatabaseError ( _ ) => * resp . status_mut ( ) = StatusCode :: INTERNAL_SERVER_ERROR , Error :: IllegalToken => * resp . status_mut ( ) = StatusCode :: UNAUTHORIZED , Error :: ExpiredToken => * resp . status_mut ( ) = StatusCode :: UNAUTHORIZED , Error :: MalformedToken => * resp . status_mut ( ) = StatusCode :: UNAUTHORIZED , Error :: NotAuthorized => * resp . status_mut ( ) = StatusCode :: FORBIDDEN , Error :: UserBanned => * resp . status_mut ( ) = StatusCode :: FORBIDDEN , Error :: BadRequest => * resp . status_mut ( ) = StatusCode :: BAD_REQUEST , Error :: NotFound => * resp . status_mut ( ) = StatusCode :: NOT_FOUND , Error :: InternalServerError => * resp . status_mut ( ) = StatusCode :: INTERNAL_SERVER_ERROR , } warn ! ( " " resp ) ; Ok ( resp ) }
Takes a rejection, which Warp would otherwise handle in its own way, and transform it into
an Ok(Reply) where the status is set to correspond to the provided error.
Takes a rejection which Warp would otherwise handle in its own way and transform it into an Ok ( Reply ) where the status is set to correspond to the provided error .
err
Rejection
err
Rejection