Skip to content

Commit

Permalink
refactor: rename error class
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavio committed Apr 5, 2024
1 parent 0d29635 commit 6ee374b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/routes/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@ impl TryFrom<FormData> 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,
}
}
}
Expand Down Expand Up @@ -75,8 +76,8 @@ pub async fn subscribe(
pool: web::Data<PgPool>,
email_client: web::Data<EmailClient>,
base_url: web::Data<ApplicationBaseUrl>,
) -> Result<HttpResponse, SubscribeError> {
let new_subscriber = form.0.try_into().map_err(SubscribeError::ValidationError)?;
) -> Result<HttpResponse, SubscriptionError> {
let new_subscriber = form.0.try_into().map_err(SubscriptionError::ValidationError)?;
let mut transaction = pool
.begin()
.await
Expand Down
1 change: 1 addition & 0 deletions src/routes/subscriptions_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Parameters {
}

#[derive(thiserror::Error)]
/// Subscription confirmation errors.
pub enum ConfirmationError {
#[error(transparent)]
UnexpectedError(#[from] anyhow::Error),
Expand Down

0 comments on commit 6ee374b

Please sign in to comment.