Merge pull request #950 from AppFlowy-IO/fix/publish-namespace-error

fix: add invalid character error for publish namespace
This commit is contained in:
Zack 2024-10-29 17:04:26 +08:00 committed by GitHub
commit 4643e568d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 4 deletions

View File

@ -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 {

View File

@ -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(())

View File

@ -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
);
}
}