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 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);

View file

@ -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",

View file

@ -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()
}
}