feat: error types for customization table constraint violoations

This commit is contained in:
Aravinth Manivannan 2024-07-16 11:19:35 +05:30
parent 5937d7a0fd
commit 66464b33f1
Signed by: realaravinth
GPG key ID: F8F50389936984FF
3 changed files with 12 additions and 0 deletions

View file

@ -19,6 +19,8 @@ impl From<SqlxError> for InventoryDBError {
return Self::DuplicateStoreID;
} else if msg.contains("cqrs_inventory_store_query_product_id_key") {
return Self::DuplicateProductID;
} else if msg.contains("cqrs_inventory_product_customizations_query_customization_id_key") {
return Self::DuplicateCustomizationID;
} else if msg.contains("cqrs_inventory_store_query_category_id_key") {
return Self::DuplicateCategoryID;
} else if msg.contains("cqrs_inventory_product_query_name_key") {
@ -27,6 +29,8 @@ impl From<SqlxError> for InventoryDBError {
return Self::DuplicateProductName;
} else if msg.contains("cqrs_inventory_store_query_name_key") {
return Self::DuplicateStoreName;
} else if msg.contains("cqrs_inventory_product_customizations_query_name_key") {
return Self::DuplicateCustomizationName
} else {
println!("{msg}");
}

View file

@ -15,5 +15,7 @@ pub enum InventoryDBError {
DuplicateStoreID,
DuplicateProductName,
DuplicateProductID,
DuplicateCustomizationID,
DuplicateCustomizationName,
InternalError,
}

View file

@ -15,6 +15,7 @@ pub enum InventoryError {
DuplicateCategoryName,
DuplicateStoreName,
DuplicateProductName,
DuplicateCustomizationName,
InternalError,
}
@ -24,6 +25,7 @@ impl From<InventoryDBError> for InventoryError {
InventoryDBError::DuplicateCategoryName => Self::DuplicateCategoryName,
InventoryDBError::DuplicateStoreName => Self::DuplicateStoreName,
InventoryDBError::DuplicateProductName => Self::DuplicateProductName,
InventoryDBError::DuplicateCustomizationName => Self::DuplicateCustomizationName,
InventoryDBError::DuplicateStoreID => {
error!("DuplicateStoreID");
Self::InternalError
@ -36,6 +38,10 @@ impl From<InventoryDBError> for InventoryError {
error!("DuplicateCategoryID");
Self::InternalError
}
InventoryDBError::DuplicateCustomizationID => {
error!("DuplicateCustomizationID");
Self::InternalError
}
InventoryDBError::InternalError => Self::InternalError,
}
}