From 4dd264a2835b39199de345875069b330629d9db3 Mon Sep 17 00:00:00 2001 From: Jacek Chmielewski Date: Tue, 24 Jan 2023 10:26:18 +0100 Subject: [PATCH] Handle JWT signing error --- avanguard/src/error.rs | 6 ++++++ avanguard/src/http.rs | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/avanguard/src/error.rs b/avanguard/src/error.rs index c1f0cdb..aba2290 100644 --- a/avanguard/src/error.rs +++ b/avanguard/src/error.rs @@ -2,6 +2,7 @@ use actix_web::{ http::{header::ContentType, StatusCode}, HttpResponse, ResponseError, }; +use openidconnect::JsonWebTokenError; use thiserror::Error; #[derive(Debug, Error)] @@ -12,6 +13,8 @@ pub enum ApiError { WalletNotFound, #[error("signature incorrect")] SignatureIncorrect, + #[error("signing error")] + SigningError(#[from] JsonWebTokenError), } impl ApiError { @@ -20,6 +23,7 @@ impl ApiError { Self::Sqlx(_) => "DB", Self::WalletNotFound => "WalletNotFound", Self::SignatureIncorrect => "SignatureIncorrect", + Self::SigningError(_) => "SignatureIncorrect", } } @@ -28,6 +32,7 @@ impl ApiError { Self::Sqlx(_) => String::from("Internal error"), Self::WalletNotFound => String::from("Wallet not found"), Self::SignatureIncorrect => String::from("Signature incorrect"), + Self::SigningError(_) => String::from("Signing error"), } } } @@ -60,6 +65,7 @@ impl ResponseError for ApiError { Self::Sqlx(_) => StatusCode::INTERNAL_SERVER_ERROR, ApiError::WalletNotFound => StatusCode::UNAUTHORIZED, ApiError::SignatureIncorrect => StatusCode::UNAUTHORIZED, + ApiError::SigningError(_) => StatusCode::UNAUTHORIZED, } } } diff --git a/avanguard/src/http.rs b/avanguard/src/http.rs index 0bbdb19..46aa8e2 100644 --- a/avanguard/src/http.rs +++ b/avanguard/src/http.rs @@ -149,9 +149,7 @@ pub async fn web3auth_end( None, &signature.nonce, &app_state.config.client_id, - ) - // TODO: handle JWT error - .unwrap(); + )?; wallet.challenge_signature = Some(signature.signature.clone()); wallet.save(&app_state.pool).await?; Ok(Json(JwtToken {