consistently name Err values err
				
					
				
			This commit is contained in:
		
							parent
							
								
									99246773ef
								
							
						
					
					
						commit
						c5c884f069
					
				
					 3 changed files with 17 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -11,6 +11,8 @@ use crate::{model::user::User, state::AppState, token::Claims};
 | 
			
		|||
 | 
			
		||||
pub struct ExtractUserToken(pub Option<User>);
 | 
			
		||||
 | 
			
		||||
pub const TOKEN_COOKIE_NAME: &'static str = "imgboard-token";
 | 
			
		||||
 | 
			
		||||
#[async_trait]
 | 
			
		||||
impl<S> FromRequestParts<S> for ExtractUserToken
 | 
			
		||||
where
 | 
			
		||||
| 
						 | 
				
			
			@ -22,8 +24,8 @@ where
 | 
			
		|||
    async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
 | 
			
		||||
        let state = match parts.extract_with_state::<AppState, _>(state).await {
 | 
			
		||||
            Ok(s) => s,
 | 
			
		||||
            Err(why) => {
 | 
			
		||||
                error!("Getting state: {}", why);
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                error!("Getting state: {}", err);
 | 
			
		||||
                return Err((StatusCode::INTERNAL_SERVER_ERROR, "Internal server error"));
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +38,7 @@ where
 | 
			
		|||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        match cookie.get("imgboard-token") {
 | 
			
		||||
        match cookie.get(TOKEN_COOKIE_NAME) {
 | 
			
		||||
            Some(token) => {
 | 
			
		||||
                let claims = Claims::decode(token, &state.decoding_key).map_err(|e| {
 | 
			
		||||
                    error!("Decoding token claims: {}", e);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,8 +26,8 @@ pub async fn get_user(
 | 
			
		|||
        .await
 | 
			
		||||
    {
 | 
			
		||||
        Ok(user) => user,
 | 
			
		||||
        Err(why) => {
 | 
			
		||||
            error!("Getting user: {}", why);
 | 
			
		||||
        Err(err) => {
 | 
			
		||||
            error!("Getting user: {}", err);
 | 
			
		||||
            return Page::new(state.hbs.render(
 | 
			
		||||
                "error.hbs",
 | 
			
		||||
                &PageData {
 | 
			
		||||
| 
						 | 
				
			
			@ -82,8 +82,8 @@ pub async fn get_user_new(
 | 
			
		|||
        .await
 | 
			
		||||
    {
 | 
			
		||||
        Ok(r) => r.count.unwrap_or(0),
 | 
			
		||||
        Err(why) => {
 | 
			
		||||
            error!("Getting user count: {}", why);
 | 
			
		||||
        Err(err) => {
 | 
			
		||||
            error!("Getting user count: {}", err);
 | 
			
		||||
            return Page::new(
 | 
			
		||||
                state
 | 
			
		||||
                    .hbs
 | 
			
		||||
| 
						 | 
				
			
			@ -118,8 +118,8 @@ pub async fn post_user_new(
 | 
			
		|||
            .await
 | 
			
		||||
        {
 | 
			
		||||
            Ok(r) => r.count.unwrap_or(0),
 | 
			
		||||
            Err(why) => {
 | 
			
		||||
                error!("Getting user count: {}", why);
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                error!("Getting user count: {}", err);
 | 
			
		||||
 | 
			
		||||
                return Page::new(state.hbs.render(
 | 
			
		||||
                    "error.hbs",
 | 
			
		||||
| 
						 | 
				
			
			@ -175,8 +175,8 @@ pub async fn post_user_new(
 | 
			
		|||
 | 
			
		||||
    let hashed_password = match bcrypt::hash(form_data.password, 12) {
 | 
			
		||||
        Ok(hash) => hash,
 | 
			
		||||
        Err(why) => {
 | 
			
		||||
            error!("Hashing password: {}", why);
 | 
			
		||||
        Err(err) => {
 | 
			
		||||
            error!("Hashing password: {}", err);
 | 
			
		||||
 | 
			
		||||
            return Page::new(state.hbs.render(
 | 
			
		||||
                "error.hbs",
 | 
			
		||||
| 
						 | 
				
			
			@ -199,8 +199,8 @@ pub async fn post_user_new(
 | 
			
		|||
    .await
 | 
			
		||||
    {
 | 
			
		||||
        Ok(u) => u,
 | 
			
		||||
        Err(why) => {
 | 
			
		||||
            error!("Creating user: {}", why);
 | 
			
		||||
        Err(err) => {
 | 
			
		||||
            error!("Creating user: {}", err);
 | 
			
		||||
 | 
			
		||||
            return Page::new(state.hbs.render(
 | 
			
		||||
                "error.hbs",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,8 +43,8 @@ impl IntoResponse for Page {
 | 
			
		|||
    fn into_response(self) -> axum::response::Response {
 | 
			
		||||
        match self.0 {
 | 
			
		||||
            Ok(s) => ([(header::CONTENT_TYPE, "text/html; charset=utf-8")], s).into_response(),
 | 
			
		||||
            Err(why) => {
 | 
			
		||||
                error!("Error rendering page: {}", why);
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                error!("Error rendering page: {}", err);
 | 
			
		||||
                (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue