Skip to content

Commit

Permalink
refactor: Exception struct name
Browse files Browse the repository at this point in the history
  • Loading branch information
bush1D3v committed Sep 7, 2024
1 parent 7956f9d commit 5e018d4
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/middlewares/auth_middleware.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
jwt_token_middleware::jwt_token_middleware, uuid_path_middleware::uuid_path_middleware,
};
use crate::shared::exceptions::exceptions::Exceptions;
use crate::shared::exceptions::exception::Exception;
use actix_web::{HttpRequest, HttpResponse};

/// Auth middleware.
Expand Down Expand Up @@ -55,7 +55,7 @@ pub async fn auth_middleware(
};

if token.claims.sub != id {
return Err(Exceptions::unauthorized(
return Err(Exception::unauthorized(
String::from("bearer token"),
String::from("O token informado não pertence ao usuário."),
None,
Expand Down
6 changes: 3 additions & 3 deletions src/middlewares/jwt_token_middleware.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::shared::{
exceptions::exceptions::Exceptions, structs::jwt_claims::Claims, treaties::jwt_treated::Jwt,
exceptions::exception::Exception, structs::jwt_claims::Claims, treaties::jwt_treated::Jwt,
};
use actix_web::{http::header::HeaderMap, HttpResponse};
use jsonwebtoken::TokenData;
Expand Down Expand Up @@ -45,14 +45,14 @@ pub fn jwt_token_middleware(headers: &HeaderMap) -> Result<TokenData<Claims>, Ht
token_str.trim()
}
Err(e) => {
return Err(Exceptions::internal_server_error(
return Err(Exception::internal_server_error(
String::from("bearer token"),
e.to_string(),
))
}
},
None => {
return Err(Exceptions::bad_request(
return Err(Exception::bad_request(
String::from("bearer token"),
String::from("O valor do cabeçalho 'Authorization' deve ser informado."),
))
Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/uuid_path_middleware.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::shared::exceptions::exceptions::Exceptions;
use crate::shared::exceptions::exception::Exception;
use actix_web::HttpResponse;

pub fn uuid_path_middleware(id: String, path_name: &str) -> Result<String, HttpResponse> {
match uuid::Uuid::parse_str(&id) {
Ok(uuid) => Ok(uuid.to_string()),
Err(_) => Err(Exceptions::unprocessable_entity(
Err(_) => Err(Exception::unprocessable_entity(
String::from(path_name),
String::from("Por favor, envie um valor de UUID válido na URL da requisição."),
Some(id),
Expand Down
6 changes: 3 additions & 3 deletions src/modules/user/user_providers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
shared::exceptions::exceptions::Exceptions,
shared::exceptions::exception::Exception,
utils::query_constructor_executor::query_constructor_executor,
};
use actix_web::{web::Data, HttpResponse};
Expand All @@ -17,7 +17,7 @@ pub async fn email_exists(postgres_pool: Data<Pool>, email: String) -> Result<()
};

if !rows.is_empty() {
return Err(Exceptions::conflict(email));
return Err(Exception::conflict(email));
}
Ok(())
}
Expand All @@ -36,7 +36,7 @@ pub async fn email_not_exists(
};

if rows.is_empty() {
return Err(Exceptions::not_found(
return Err(Exception::not_found(
String::from("email"),
String::from("Não foi encontrado um usuário com este e-mail."),
Some(email),
Expand Down
10 changes: 5 additions & 5 deletions src/modules/user/user_repositories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::{
user_queues::{DeleteUserAppQueue, InsertUserAppQueue, PutUserAppQueue},
};
use crate::{
shared::{exceptions::exceptions::Exceptions, structs::query_params::QueryParams},
shared::{exceptions::exception::Exception, structs::query_params::QueryParams},
utils::query_constructor_executor::query_constructor_executor,
};
use actix_web::{
Expand Down Expand Up @@ -42,7 +42,7 @@ pub async fn get_user_salt_repository(
};

if rows.is_empty() {
return Err(Exceptions::internal_server_error(
return Err(Exception::internal_server_error(
String::from("server"),
String::from("Erro inesperado no servidor. Tente novamente mais tarde."),
));
Expand Down Expand Up @@ -88,7 +88,7 @@ pub async fn login_user_repository(
};

if rows.is_empty() {
return Err(Exceptions::not_found(
return Err(Exception::not_found(
String::from("user"),
String::from("Não foi encontrado um usuário com este e-mail."),
Some(email),
Expand All @@ -111,7 +111,7 @@ pub async fn detail_user_repository(
};

if rows.is_empty() {
return Err(Exceptions::not_found(
return Err(Exception::not_found(
String::from("user"),
String::from("Não foi encontrado um usuário com este id."),
Some(user_id),
Expand Down Expand Up @@ -154,7 +154,7 @@ pub async fn list_users_repository(
};

if rows.is_empty() {
return Err(Exceptions::not_found(
return Err(Exception::not_found(
String::from("users"),
String::from("Não foram encontrados usuários."),
None,
Expand Down
6 changes: 3 additions & 3 deletions src/modules/user/user_serdes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::user_dtos::UserDTO;
use crate::shared::exceptions::exceptions::Exceptions;
use crate::shared::exceptions::exception::Exception;
use actix_web::HttpResponse;

pub struct UserSerdes;
Expand All @@ -8,7 +8,7 @@ impl UserSerdes {
pub fn serde_json_to_string(user: &UserDTO) -> Result<String, HttpResponse> {
match serde_json::to_string(user) {
Ok(x) => Ok(x),
Err(e) => Err(Exceptions::internal_server_error(
Err(e) => Err(Exception::internal_server_error(
String::from("server"),
e.to_string(),
)),
Expand All @@ -18,7 +18,7 @@ impl UserSerdes {
pub fn serde_string_to_json(user: &str) -> Result<UserDTO, HttpResponse> {
match serde_json::from_str(user) {
Ok(x) => Ok(x),
Err(e) => Err(Exceptions::internal_server_error(
Err(e) => Err(Exception::internal_server_error(
String::from("server"),
e.to_string(),
)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::utils::error_construct::error_construct;
use actix_web::HttpResponse;

pub struct Exceptions;
pub struct Exception;

impl Exceptions {
impl Exception {
/// Error 400
pub fn bad_request(data: String, message: String) -> HttpResponse {
HttpResponse::BadRequest().json(error_construct(
Expand Down
2 changes: 1 addition & 1 deletion src/shared/exceptions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod custom_error_to_io_error_kind;
pub mod exceptions;
pub mod exception;
10 changes: 5 additions & 5 deletions src/shared/treaties/bcrypt_treated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use actix_web::HttpResponse;
use bcrypt::DEFAULT_COST;

use crate::shared::exceptions::exceptions::Exceptions;
use crate::shared::exceptions::exception::Exception;

pub struct Bcrypt {}

Expand All @@ -19,18 +19,18 @@ impl Bcrypt {
match bcrypt::verify(password, hash) {
Ok(true) => Ok(()),
Ok(false) => match data {
BcryptVerifyData::EmailPassword(email, password) => Err(Exceptions::unauthorized(
BcryptVerifyData::EmailPassword(email, password) => Err(Exception::unauthorized(
String::from("email/password"),
String::from("E-mail e/ou senha incorretos."),
Some(format!("{}/{}", email, password)),
)),
BcryptVerifyData::Password(password) => Err(Exceptions::unauthorized(
BcryptVerifyData::Password(password) => Err(Exception::unauthorized(
String::from("password"),
String::from("Senha incorreta."),
Some(password),
)),
},
Err(e) => Err(Exceptions::internal_server_error(
Err(e) => Err(Exception::internal_server_error(
String::from("bcrypt"),
e.to_string(),
)),
Expand All @@ -39,7 +39,7 @@ impl Bcrypt {
pub fn hash(password: &str) -> Result<String, HttpResponse> {
match bcrypt::hash(password, DEFAULT_COST - 4) {
Ok(hash) => Ok(hash),
Err(e) => Err(Exceptions::internal_server_error(
Err(e) => Err(Exception::internal_server_error(
String::from("bcrypt"),
e.to_string(),
)),
Expand Down
10 changes: 5 additions & 5 deletions src/shared/treaties/jwt_treated.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::shared::{exceptions::exceptions::Exceptions, structs::jwt_claims::Claims};
use crate::shared::{exceptions::exception::Exception, structs::jwt_claims::Claims};
use actix_web::HttpResponse;
use jsonwebtoken::TokenData;
use std::env;
Expand All @@ -19,7 +19,7 @@ impl Jwt {
&jsonwebtoken::EncodingKey::from_secret(env::var("JWT_REFRESH_KEY").unwrap().as_ref()),
) {
Ok(token) => Ok(token),
Err(e) => Err(Exceptions::internal_server_error(
Err(e) => Err(Exception::internal_server_error(
String::from("jsonwebtoken"),
e.to_string(),
)),
Expand All @@ -39,7 +39,7 @@ impl Jwt {
&jsonwebtoken::EncodingKey::from_secret(env::var("JWT_ACCESS_KEY").unwrap().as_ref()),
) {
Ok(token) => Ok(token),
Err(e) => Err(Exceptions::internal_server_error(
Err(e) => Err(Exception::internal_server_error(
String::from("jsonwebtoken"),
e.to_string(),
)),
Expand All @@ -55,7 +55,7 @@ impl Jwt {
&jsonwebtoken::Validation::default(),
) {
Ok(token) => Ok(token),
Err(e) => Err(Exceptions::unauthorized(
Err(e) => Err(Exception::unauthorized(
String::from("bearer token"),
e.to_string(),
None,
Expand All @@ -72,7 +72,7 @@ impl Jwt {
&jsonwebtoken::Validation::default(),
) {
Ok(token) => Ok(token),
Err(e) => Err(Exceptions::unauthorized(
Err(e) => Err(Exception::unauthorized(
String::from("bearer token"),
e.to_string(),
None,
Expand Down
4 changes: 2 additions & 2 deletions src/shared/treaties/strip_suffix_treated.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::shared::exceptions::exceptions::Exceptions;
use crate::shared::exceptions::exception::Exception;
use actix_web::HttpResponse;

pub struct StripSuffix {}
Expand All @@ -7,7 +7,7 @@ impl StripSuffix {
pub fn strip_suffix(input: String, suffix: &str) -> Result<String, HttpResponse> {
match input.strip_suffix(suffix) {
Some(input_suffixed) => Ok(input_suffixed.to_string()),
None => Err(Exceptions::internal_server_error(
None => Err(Exception::internal_server_error(
String::from("server"),
String::from("Erro ao extrair o salt do usuário."),
)),
Expand Down

0 comments on commit 5e018d4

Please sign in to comment.