diff --git a/src/api/auth/utils.rs b/src/api/auth/utils.rs index 68ecc5f..0f31d0a 100644 --- a/src/api/auth/utils.rs +++ b/src/api/auth/utils.rs @@ -71,7 +71,7 @@ pub async fn get_user_by_username_and_password( password: &str, ) -> ApiResult { if username.is_empty() || password.is_empty() { - return Err(ApiError::BAdRequest( + return Err(ApiError::BadRequest( "Invalid username or password, must be not empty".to_owned(), )); } diff --git a/src/api/todo/utils.rs b/src/api/todo/utils.rs index 6fd2cb4..aa30be9 100644 --- a/src/api/todo/utils.rs +++ b/src/api/todo/utils.rs @@ -110,14 +110,14 @@ pub async fn update_todo( ) -> ApiResult { if let Some(title) = &title { if title.is_empty() { - return Err(ApiError::BAdRequest("The todo title is empty".to_string())); + return Err(ApiError::BadRequest("The todo title is empty".to_string())); } else if is_todo_title_exists(title, todo.user_id, db).await? { - return Err(ApiError::BAdRequest(format!( + return Err(ApiError::BadRequest(format!( "The todo `{}` is already exists", title ))); } else if title.chars().count() > max_todo_title_length() as usize { - return Err(ApiError::BAdRequest(format!( + return Err(ApiError::BadRequest(format!( "The todo title length must be less than {}", max_todo_title_length() ))); @@ -141,14 +141,14 @@ pub async fn create_todo( user_id: u32, ) -> ApiResult { if todo_content.title.is_empty() { - return Err(ApiError::BAdRequest("The todo title is empty".to_string())); + return Err(ApiError::BadRequest("The todo title is empty".to_string())); } else if is_todo_title_exists(&todo_content.title, user_id, db).await? { - return Err(ApiError::BAdRequest(format!( + return Err(ApiError::BadRequest(format!( "The todo `{}` is already exists", todo_content.title ))); } else if todo_content.title.chars().count() > max_todo_title_length() as usize { - return Err(ApiError::BAdRequest(format!( + return Err(ApiError::BadRequest(format!( "The todo title length must be less than {}", max_todo_title_length() ))); @@ -159,7 +159,7 @@ pub async fn create_todo( .database_err()? > max_todos_count() { - return Err(ApiError::BAdRequest(format!( + return Err(ApiError::BadRequest(format!( "The maximum number of todos is {}", max_todos_count() ))); diff --git a/src/errors.rs b/src/errors.rs index f27f045..eedb833 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -12,7 +12,7 @@ pub enum Error { #[error("{0}")] InternalServer(String), #[error("{0}")] - BAdRequest(String), + BadRequest(String), #[error("{0}")] NotFound(String), #[error("{0}")] @@ -46,7 +46,7 @@ impl ErrorTrait for std::result::Result { } fn bad_request_err(self, message: &str) -> Self::Output { - self.map_err(|_| Error::BAdRequest(message.to_string())) + self.map_err(|_| Error::BadRequest(message.to_string())) } fn not_found_err(self, message: &str) -> Self::Output { @@ -121,8 +121,8 @@ impl ErrorTrait for Option { impl From for Error { fn from(err: QueryPayloadError) -> Self { match err { - QueryPayloadError::Deserialize(err) => Self::BAdRequest(err.to_string()), - _ => Self::BAdRequest("The parameters query are invalid".to_string()), + QueryPayloadError::Deserialize(err) => Self::BadRequest(err.to_string()), + _ => Self::BadRequest("The parameters query are invalid".to_string()), } } } @@ -131,12 +131,12 @@ impl From for Error { fn from(err: JsonPayloadError) -> Self { match err { JsonPayloadError::ContentType => { - Self::BAdRequest("The content type is not `application/json`".to_string()) + Self::BadRequest("The content type is not `application/json`".to_string()) } JsonPayloadError::Deserialize(err) => { - Self::BAdRequest(format!("The request body is invalid: {err}")) + Self::BadRequest(format!("The request body is invalid: {err}")) } - _ => Self::BAdRequest("The request body is invalid".to_string()), + _ => Self::BadRequest("The request body is invalid".to_string()), } } } @@ -145,7 +145,7 @@ impl ResponseError for Error { fn status_code(&self) -> StatusCode { match self { Self::InternalServer(_) => StatusCode::INTERNAL_SERVER_ERROR, - Self::BAdRequest(_) => StatusCode::BAD_REQUEST, + Self::BadRequest(_) => StatusCode::BAD_REQUEST, Self::NotFound(_) => StatusCode::NOT_FOUND, Self::Forbidden(_) => StatusCode::FORBIDDEN, Self::Unauthorized(_) => StatusCode::UNAUTHORIZED, diff --git a/src/schemas/auth/register.rs b/src/schemas/auth/register.rs index ef37bca..4c1bf75 100644 --- a/src/schemas/auth/register.rs +++ b/src/schemas/auth/register.rs @@ -25,7 +25,7 @@ pub struct RegisterSchema { impl RegisterSchema { pub async fn create(&self, db: &DatabaseConnection) -> ApiResult { if self.username.is_empty() || self.password.is_empty() { - return Err(ApiError::BAdRequest( + return Err(ApiError::BadRequest( "Invalid username or password, must be not empty".to_owned(), )); } @@ -45,7 +45,7 @@ impl RegisterSchema { .map_err(|db_err| { if let DbErr::Exec(RuntimeErr::SqlxError(SqlxError::Database(e))) = db_err { if e.code() == Some(Cow::Borrowed("2067")) { - return ApiError::BAdRequest(format!( + return ApiError::BadRequest(format!( "Username {} already exists", self.username ));