fix: add invalid character error for publish namespace
This commit is contained in:
parent
33db915b44
commit
855cc58ad8
|
|
@ -170,6 +170,9 @@ pub enum AppError {
|
||||||
given_length: usize,
|
given_length: usize,
|
||||||
max_length: usize,
|
max_length: usize,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
#[error("There is an invalid character in the publish namespace: {character}")]
|
||||||
|
CustomNamespaceInvalidCharacter { character: char },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppError {
|
impl AppError {
|
||||||
|
|
@ -243,6 +246,9 @@ impl AppError {
|
||||||
AppError::PublishNameAlreadyExists { .. } => ErrorCode::PublishNameAlreadyExists,
|
AppError::PublishNameAlreadyExists { .. } => ErrorCode::PublishNameAlreadyExists,
|
||||||
AppError::PublishNameInvalidCharacter { .. } => ErrorCode::PublishNameInvalidCharacter,
|
AppError::PublishNameInvalidCharacter { .. } => ErrorCode::PublishNameInvalidCharacter,
|
||||||
AppError::PublishNameTooLong { .. } => ErrorCode::PublishNameTooLong,
|
AppError::PublishNameTooLong { .. } => ErrorCode::PublishNameTooLong,
|
||||||
|
AppError::CustomNamespaceInvalidCharacter { .. } => {
|
||||||
|
ErrorCode::CustomNamespaceInvalidCharacter
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -381,6 +387,7 @@ pub enum ErrorCode {
|
||||||
PublishNameAlreadyExists = 1050,
|
PublishNameAlreadyExists = 1050,
|
||||||
PublishNameInvalidCharacter = 1051,
|
PublishNameInvalidCharacter = 1051,
|
||||||
PublishNameTooLong = 1052,
|
PublishNameTooLong = 1052,
|
||||||
|
CustomNamespaceInvalidCharacter = 1053,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ErrorCode {
|
impl ErrorCode {
|
||||||
|
|
|
||||||
|
|
@ -216,9 +216,7 @@ async fn check_workspace_namespace(new_namespace: &str) -> Result<(), AppError>
|
||||||
// Only contain alphanumeric characters and hyphens
|
// Only contain alphanumeric characters and hyphens
|
||||||
for c in new_namespace.chars() {
|
for c in new_namespace.chars() {
|
||||||
if !c.is_alphanumeric() && c != '-' {
|
if !c.is_alphanumeric() && c != '-' {
|
||||||
return Err(AppError::InvalidRequest(
|
return Err(AppError::CustomNamespaceInvalidCharacter { character: c });
|
||||||
"Namespace must only contain alphanumeric characters and hyphens".to_string(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,12 @@ async fn test_set_publish_namespace_set() {
|
||||||
.await
|
.await
|
||||||
.err()
|
.err()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(err.code, ErrorCode::InvalidRequest, "{:?}", err);
|
assert_eq!(
|
||||||
|
err.code,
|
||||||
|
ErrorCode::CustomNamespaceInvalidCharacter,
|
||||||
|
"{:?}",
|
||||||
|
err
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue