From 6ee374b915d6b76dce9971e07251e271873567cd Mon Sep 17 00:00:00 2001 From: alexsavio Date: Fri, 5 Apr 2024 09:50:26 +0200 Subject: [PATCH] refactor: rename error class --- src/routes/subscriptions.rs | 15 ++++++++------- src/routes/subscriptions_confirm.rs | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/routes/subscriptions.rs b/src/routes/subscriptions.rs index 9fc518a..fb243be 100644 --- a/src/routes/subscriptions.rs +++ b/src/routes/subscriptions.rs @@ -30,24 +30,25 @@ impl TryFrom for NewSubscriber { } #[derive(thiserror::Error)] -pub enum SubscribeError { +/// Subscription errors. +pub enum SubscriptionError { #[error("{0}")] ValidationError(String), #[error(transparent)] UnexpectedError(#[from] anyhow::Error), } -impl std::fmt::Debug for SubscribeError { +impl std::fmt::Debug for SubscriptionError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { error_chain_fmt(self, f) } } -impl ResponseError for SubscribeError { +impl ResponseError for SubscriptionError { fn status_code(&self) -> StatusCode { match self { - SubscribeError::ValidationError(_) => StatusCode::BAD_REQUEST, - SubscribeError::UnexpectedError(_) => StatusCode::INTERNAL_SERVER_ERROR, + SubscriptionError::ValidationError(_) => StatusCode::BAD_REQUEST, + SubscriptionError::UnexpectedError(_) => StatusCode::INTERNAL_SERVER_ERROR, } } } @@ -75,8 +76,8 @@ pub async fn subscribe( pool: web::Data, email_client: web::Data, base_url: web::Data, -) -> Result { - let new_subscriber = form.0.try_into().map_err(SubscribeError::ValidationError)?; +) -> Result { + let new_subscriber = form.0.try_into().map_err(SubscriptionError::ValidationError)?; let mut transaction = pool .begin() .await diff --git a/src/routes/subscriptions_confirm.rs b/src/routes/subscriptions_confirm.rs index c64e297..057efc9 100644 --- a/src/routes/subscriptions_confirm.rs +++ b/src/routes/subscriptions_confirm.rs @@ -11,6 +11,7 @@ pub struct Parameters { } #[derive(thiserror::Error)] +/// Subscription confirmation errors. pub enum ConfirmationError { #[error(transparent)] UnexpectedError(#[from] anyhow::Error),