Skip to content

Commit

Permalink
Fix typo BAdRequest -> BadRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAwiteb committed Feb 17, 2023
1 parent 99c12df commit efcc5bc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/api/auth/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn get_user_by_username_and_password(
password: &str,
) -> ApiResult<UserModel> {
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(),
));
}
Expand Down
14 changes: 7 additions & 7 deletions src/api/todo/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ pub async fn update_todo(
) -> ApiResult<TodoModel> {
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()
)));
Expand All @@ -141,14 +141,14 @@ pub async fn create_todo(
user_id: u32,
) -> ApiResult<TodoSchema> {
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()
)));
Expand All @@ -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()
)));
Expand Down
16 changes: 8 additions & 8 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Error {
#[error("{0}")]
InternalServer(String),
#[error("{0}")]
BAdRequest(String),
BadRequest(String),
#[error("{0}")]
NotFound(String),
#[error("{0}")]
Expand Down Expand Up @@ -46,7 +46,7 @@ impl<T, E> ErrorTrait for std::result::Result<T, E> {
}

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 {
Expand Down Expand Up @@ -121,8 +121,8 @@ impl<T> ErrorTrait for Option<T> {
impl From<QueryPayloadError> 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()),
}
}
}
Expand All @@ -131,12 +131,12 @@ impl From<JsonPayloadError> 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()),
}
}
}
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/auth/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct RegisterSchema {
impl RegisterSchema {
pub async fn create(&self, db: &DatabaseConnection) -> ApiResult<UserSchema> {
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(),
));
}
Expand All @@ -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
));
Expand Down

0 comments on commit efcc5bc

Please sign in to comment.