diff --git a/libs/app-error/src/lib.rs b/libs/app-error/src/lib.rs index d74dd029..5ee18997 100644 --- a/libs/app-error/src/lib.rs +++ b/libs/app-error/src/lib.rs @@ -170,6 +170,9 @@ pub enum AppError { given_length: usize, max_length: usize, }, + + #[error("There is an invalid character in the publish namespace: {character}")] + CustomNamespaceInvalidCharacter { character: char }, } impl AppError { @@ -243,6 +246,9 @@ impl AppError { AppError::PublishNameAlreadyExists { .. } => ErrorCode::PublishNameAlreadyExists, AppError::PublishNameInvalidCharacter { .. } => ErrorCode::PublishNameInvalidCharacter, AppError::PublishNameTooLong { .. } => ErrorCode::PublishNameTooLong, + AppError::CustomNamespaceInvalidCharacter { .. } => { + ErrorCode::CustomNamespaceInvalidCharacter + }, } } } @@ -381,6 +387,7 @@ pub enum ErrorCode { PublishNameAlreadyExists = 1050, PublishNameInvalidCharacter = 1051, PublishNameTooLong = 1052, + CustomNamespaceInvalidCharacter = 1053, } impl ErrorCode { diff --git a/src/biz/workspace/publish.rs b/src/biz/workspace/publish.rs index 9ca6149f..06acb605 100644 --- a/src/biz/workspace/publish.rs +++ b/src/biz/workspace/publish.rs @@ -216,9 +216,7 @@ async fn check_workspace_namespace(new_namespace: &str) -> Result<(), AppError> // Only contain alphanumeric characters and hyphens for c in new_namespace.chars() { if !c.is_alphanumeric() && c != '-' { - return Err(AppError::InvalidRequest( - "Namespace must only contain alphanumeric characters and hyphens".to_string(), - )); + return Err(AppError::CustomNamespaceInvalidCharacter { character: c }); } } Ok(()) diff --git a/tests/workspace/publish.rs b/tests/workspace/publish.rs index 1f1eafa8..424cca3f 100644 --- a/tests/workspace/publish.rs +++ b/tests/workspace/publish.rs @@ -77,7 +77,12 @@ async fn test_set_publish_namespace_set() { .await .err() .unwrap(); - assert_eq!(err.code, ErrorCode::InvalidRequest, "{:?}", err); + assert_eq!( + err.code, + ErrorCode::CustomNamespaceInvalidCharacter, + "{:?}", + err + ); } }