consistently name Err values err

This commit is contained in:
sam 2023-10-23 01:53:05 +02:00
parent 99246773ef
commit c5c884f069
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
3 changed files with 17 additions and 15 deletions

View file

@ -11,6 +11,8 @@ use crate::{model::user::User, state::AppState, token::Claims};
pub struct ExtractUserToken(pub Option<User>); pub struct ExtractUserToken(pub Option<User>);
pub const TOKEN_COOKIE_NAME: &'static str = "imgboard-token";
#[async_trait] #[async_trait]
impl<S> FromRequestParts<S> for ExtractUserToken impl<S> FromRequestParts<S> for ExtractUserToken
where where
@ -22,8 +24,8 @@ where
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> { async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let state = match parts.extract_with_state::<AppState, _>(state).await { let state = match parts.extract_with_state::<AppState, _>(state).await {
Ok(s) => s, Ok(s) => s,
Err(why) => { Err(err) => {
error!("Getting state: {}", why); error!("Getting state: {}", err);
return Err((StatusCode::INTERNAL_SERVER_ERROR, "Internal server error")); 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) => { Some(token) => {
let claims = Claims::decode(token, &state.decoding_key).map_err(|e| { let claims = Claims::decode(token, &state.decoding_key).map_err(|e| {
error!("Decoding token claims: {}", e); error!("Decoding token claims: {}", e);

View file

@ -26,8 +26,8 @@ pub async fn get_user(
.await .await
{ {
Ok(user) => user, Ok(user) => user,
Err(why) => { Err(err) => {
error!("Getting user: {}", why); error!("Getting user: {}", err);
return Page::new(state.hbs.render( return Page::new(state.hbs.render(
"error.hbs", "error.hbs",
&PageData { &PageData {
@ -82,8 +82,8 @@ pub async fn get_user_new(
.await .await
{ {
Ok(r) => r.count.unwrap_or(0), Ok(r) => r.count.unwrap_or(0),
Err(why) => { Err(err) => {
error!("Getting user count: {}", why); error!("Getting user count: {}", err);
return Page::new( return Page::new(
state state
.hbs .hbs
@ -118,8 +118,8 @@ pub async fn post_user_new(
.await .await
{ {
Ok(r) => r.count.unwrap_or(0), Ok(r) => r.count.unwrap_or(0),
Err(why) => { Err(err) => {
error!("Getting user count: {}", why); error!("Getting user count: {}", err);
return Page::new(state.hbs.render( return Page::new(state.hbs.render(
"error.hbs", "error.hbs",
@ -175,8 +175,8 @@ pub async fn post_user_new(
let hashed_password = match bcrypt::hash(form_data.password, 12) { let hashed_password = match bcrypt::hash(form_data.password, 12) {
Ok(hash) => hash, Ok(hash) => hash,
Err(why) => { Err(err) => {
error!("Hashing password: {}", why); error!("Hashing password: {}", err);
return Page::new(state.hbs.render( return Page::new(state.hbs.render(
"error.hbs", "error.hbs",
@ -199,8 +199,8 @@ pub async fn post_user_new(
.await .await
{ {
Ok(u) => u, Ok(u) => u,
Err(why) => { Err(err) => {
error!("Creating user: {}", why); error!("Creating user: {}", err);
return Page::new(state.hbs.render( return Page::new(state.hbs.render(
"error.hbs", "error.hbs",

View file

@ -43,8 +43,8 @@ impl IntoResponse for Page {
fn into_response(self) -> axum::response::Response { fn into_response(self) -> axum::response::Response {
match self.0 { match self.0 {
Ok(s) => ([(header::CONTENT_TYPE, "text/html; charset=utf-8")], s).into_response(), Ok(s) => ([(header::CONTENT_TYPE, "text/html; charset=utf-8")], s).into_response(),
Err(why) => { Err(err) => {
error!("Error rendering page: {}", why); error!("Error rendering page: {}", err);
(StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response() (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response()
} }
} }