Merge pull request #950 from AppFlowy-IO/fix/publish-namespace-error
fix: add invalid character error for publish namespace
This commit is contained in:
commit
4643e568d2
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue