feat: database errors
This commit is contained in:
parent
38d897023c
commit
dcb11a4d11
3 changed files with 42 additions and 9 deletions
|
@ -32,6 +32,30 @@ pub enum DBError {
|
|||
#[error("DNS challenge hostname is already taken")]
|
||||
DuplicateChallengeHostname,
|
||||
|
||||
/// Hostname is already taken
|
||||
#[error("Hostname is already taken")]
|
||||
DuplicateHostname,
|
||||
|
||||
/// Forge Type is already taken
|
||||
#[error("Forge Type is already taken")]
|
||||
DuplicateForgeType,
|
||||
|
||||
/// HTML link Type is already taken
|
||||
#[error("User HTML link is already taken")]
|
||||
DuplicateUserLink,
|
||||
|
||||
/// User profile photo link Type is already taken
|
||||
#[error("User profile photo link is already taken")]
|
||||
DuplicateProfilePhotoLink,
|
||||
|
||||
/// Topic is already taken
|
||||
#[error("Topic is already taken")]
|
||||
DuplicateTopic,
|
||||
|
||||
/// Repository link is already taken
|
||||
#[error("Repository link is already taken")]
|
||||
DuplicateRepositoryLink,
|
||||
|
||||
/// forge instance type is unknown
|
||||
#[error("Unknown forge instance specifier {}", _0)]
|
||||
UnknownForgeType(String),
|
||||
|
|
|
@ -26,7 +26,7 @@ pub async fn adding_forge_works<'a, T: SCDatabase>(
|
|||
add_user_msg2: AddUser<'a>,
|
||||
add_repo_msg: AddRepository<'a>,
|
||||
) {
|
||||
let _ = db.delete_forge_instance(&create_forge_msg.hostname).await;
|
||||
let _ = db.delete_forge_instance(create_forge_msg.hostname).await;
|
||||
db.create_forge_isntance(&create_forge_msg).await.unwrap();
|
||||
assert!(
|
||||
db.forge_exists(create_forge_msg.hostname).await.unwrap(),
|
||||
|
|
|
@ -23,20 +23,29 @@ pub fn map_register_err(e: Error) -> DBError {
|
|||
if let Error::Database(err) = e {
|
||||
if err.code() == Some(Cow::from("2067")) {
|
||||
let msg = err.message();
|
||||
unimplemented!("deal with errors upon insertaion of duplicate values");
|
||||
println!("{}", msg);
|
||||
println!("db err: {msg}");
|
||||
if msg.contains("starchart_dns_challenges.hostname") {
|
||||
unimplemented!()
|
||||
DBError::DuplicateChallengeHostname
|
||||
} else if msg.contains("starchart_forges.hostname") {
|
||||
DBError::DuplicateHostname
|
||||
} else if msg.contains("starchart_dns_challenges.challenge") {
|
||||
unimplemented!()
|
||||
DBError::DuplicateChallengeText
|
||||
} else if msg.contains("starchart_users.html_url") {
|
||||
unimplemented!()
|
||||
DBError::DuplicateUserLink
|
||||
} else if msg.contains("starchart_project_topics.name") {
|
||||
unimplemented!()
|
||||
DBError::DuplicateTopic
|
||||
} else if msg.contains("starchart_repositories.html_url") {
|
||||
unimplemented!()
|
||||
DBError::DuplicateRepositoryLink
|
||||
} else if msg.contains("starchart_forge_type.name") {
|
||||
unimplemented!()
|
||||
DBError::DuplicateForgeType
|
||||
} else if msg.contains("starchart_users.html_url") {
|
||||
DBError::DuplicateUserLink
|
||||
} else if msg.contains("starchart_users.profile_photo_html_url") {
|
||||
DBError::DuplicateProfilePhotoLink
|
||||
} else if msg.contains("starchart_project_topics.name") {
|
||||
DBError::DuplicateTopic
|
||||
} else if msg.contains("starchart_repositories.name") {
|
||||
DBError::DuplicateRepositoryLink
|
||||
} else {
|
||||
DBError::DBError(Box::new(Error::Database(err)).into())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue