From 00cd4270b4a7808ff140f55dc6b81d12e62fe999 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 6 Apr 2026 23:24:27 -0400 Subject: [PATCH] cleanup errors --- .../avt_cookie_payload_error.rs | 21 +++++++++ .../http_user_session_payload_error.rs | 21 +++++++++ .../advanced_common_web_error.rs | 43 ++++--------------- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/crates/lib/actix_artcraft/src/sessions/anonymous_visitor_tracking/avt_cookie_payload_error.rs b/crates/lib/actix_artcraft/src/sessions/anonymous_visitor_tracking/avt_cookie_payload_error.rs index ee82d2d428..25e5bd36db 100644 --- a/crates/lib/actix_artcraft/src/sessions/anonymous_visitor_tracking/avt_cookie_payload_error.rs +++ b/crates/lib/actix_artcraft/src/sessions/anonymous_visitor_tracking/avt_cookie_payload_error.rs @@ -15,6 +15,27 @@ pub enum AvtCookiePayloadError { JwtSigner(JwtSignerError), } +impl AvtCookiePayloadError { + pub fn is_server_error(&self) -> bool { + match self { + // JWT verify errors (eg. forged cookies) → 400 bad input. + AvtCookiePayloadError::JwtSigner(JwtSignerError::JwtVerifyError(_)) => { + false + }, + // Server-side JWT signer failures (bad HMAC config, signing failure) → 500. + AvtCookiePayloadError::JwtSigner( + JwtSignerError::JwtInvalidKeyLength | JwtSignerError::JwtSignError(_) + ) => { + true + }, + // Other payload decode failures (how did these make it into the wild!?) → 500 + AvtCookiePayloadError::MissingField(_) | AvtCookiePayloadError::PayloadDecodeError(_) => { + true + } + } + } +} + impl Display for AvtCookiePayloadError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { diff --git a/crates/lib/actix_artcraft/src/sessions/user_sessions/http_user_session_payload_error.rs b/crates/lib/actix_artcraft/src/sessions/user_sessions/http_user_session_payload_error.rs index aa9076927c..1f42e2e2e5 100644 --- a/crates/lib/actix_artcraft/src/sessions/user_sessions/http_user_session_payload_error.rs +++ b/crates/lib/actix_artcraft/src/sessions/user_sessions/http_user_session_payload_error.rs @@ -12,6 +12,27 @@ pub enum HttpUserSessionPayloadError { JwtSigner(JwtSignerError), } +impl HttpUserSessionPayloadError { + pub fn is_server_error(&self) -> bool { + match self { + // Client HTTP header errors → 400 bad input. + HttpUserSessionPayloadError::HttpSessionHeaderError(_) => { + false + } + // JWT verify errors (eg. forged cookies) → 400 bad input. + HttpUserSessionPayloadError::JwtSigner(JwtSignerError::JwtVerifyError(_)) => { + false + } + // Server-side JWT signer failures (bad HMAC config, signing failure) → 500. + HttpUserSessionPayloadError::JwtSigner( + JwtSignerError::JwtInvalidKeyLength | JwtSignerError::JwtSignError(_) + ) => { + true + }, + } + } +} + impl Display for HttpUserSessionPayloadError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { diff --git a/crates/service/web/storyteller_web/src/http_server/common_responses/advanced_common_web_error.rs b/crates/service/web/storyteller_web/src/http_server/common_responses/advanced_common_web_error.rs index 1bf89948a4..e365ad9b2d 100644 --- a/crates/service/web/storyteller_web/src/http_server/common_responses/advanced_common_web_error.rs +++ b/crates/service/web/storyteller_web/src/http_server/common_responses/advanced_common_web_error.rs @@ -9,7 +9,6 @@ use actix_artcraft::sessions::user_sessions::http_user_session_payload_error::Ht use actix_http::StatusCode; use actix_web::{HttpResponse, HttpResponseBuilder, ResponseError}; use anyhow::anyhow; -use jwt_signer::jwt_signer_error::JwtSignerError; /// An error type for actix-web handlers that wraps causal errors for debugging /// and paging while presenting safe, generic HTTP responses to users. @@ -200,45 +199,21 @@ impl From for AdvancedCommonWebError { } impl From for AdvancedCommonWebError { - fn from(value: HttpUserSessionPayloadError) -> Self { - match &value { - // Client HTTP header errors → 400 bad input. - HttpUserSessionPayloadError::HttpSessionHeaderError(_) => { - Self::BadInputWithSimpleMessage("invalid session".to_string()) - } - // JWT verify errors (eg. forged cookies) → 400 bad input. - HttpUserSessionPayloadError::JwtSigner(JwtSignerError::JwtVerifyError(_)) => { - Self::BadInputWithSimpleMessage("invalid session".to_string()) - } - // Server-side JWT signer failures (bad HMAC config, signing failure) → 500. - HttpUserSessionPayloadError::JwtSigner( - JwtSignerError::JwtInvalidKeyLength - | JwtSignerError::JwtSignError(_) - ) => { - Self::from_error(value) - }, + fn from(err: HttpUserSessionPayloadError) -> Self { + if err.is_server_error() { + Self::from_error(err) + } else { + Self::BadInputWithSimpleMessage("invalid session".to_string()) } } } impl From for AdvancedCommonWebError { fn from(err: AvtCookiePayloadError) -> Self { - match &err { - // JWT verify errors (eg. forged cookies) → 400 bad input. - AvtCookiePayloadError::JwtSigner(JwtSignerError::JwtVerifyError(_)) => { - Self::BadInputWithSimpleMessage("invalid AVT cookie".to_string()) - } - // Server-side JWT signer failures (bad HMAC config, signing failure) → 500. - AvtCookiePayloadError::JwtSigner( - JwtSignerError::JwtInvalidKeyLength - | JwtSignerError::JwtSignError(_), - ) => { - Self::from_error(err) - }, - // Other payload decode failures (how did these make it into the wild!?) → 500 - AvtCookiePayloadError::MissingField(_) | AvtCookiePayloadError::PayloadDecodeError(_) => { - Self::from_error(err) - } + if err.is_server_error() { + Self::from_error(err) + } else { + Self::BadInputWithSimpleMessage("invalid AVT cookie".to_string()) } } }