aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/api_entity_crud.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-12-14 19:17:55 +0800
committerBryan Newbold <bnewbold@robocracy.org>2018-12-14 19:17:55 +0800
commit28880401a4d64f9cc1317a3f3bf515166a812c1b (patch)
tree1b2d85114fe7f0aacf26ab6185d4b1fa2718321c /rust/src/api_entity_crud.rs
parent99e9fe5fa4fa049b988cc8e7d0def5af43b7a323 (diff)
downloadfatcat-28880401a4d64f9cc1317a3f3bf515166a812c1b.tar.gz
fatcat-28880401a4d64f9cc1317a3f3bf515166a812c1b.zip
better return status for some error conditions
Diffstat (limited to 'rust/src/api_entity_crud.rs')
-rw-r--r--rust/src/api_entity_crud.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/rust/src/api_entity_crud.rs b/rust/src/api_entity_crud.rs
index 8770644c..ccbae26d 100644
--- a/rust/src/api_entity_crud.rs
+++ b/rust/src/api_entity_crud.rs
@@ -183,13 +183,10 @@ macro_rules! generic_db_update {
($ident_table: ident, $edit_table: ident) => {
fn db_update(&self, conn: &DbConn, edit_context: &EditContext, ident: FatCatId) -> Result<Self::EditRow> {
let current: Self::IdentRow = $ident_table::table.find(ident.to_uuid()).first(conn)?;
+ // TODO: is this actually true? or should we allow updates in the same editgroup?
if current.is_live != true {
- // TODO: what if isn't live? 4xx not 5xx
- bail!("can't delete an entity that doesn't exist yet");
- }
- if current.rev_id.is_none() {
- // TODO: what if it's already deleted? 4xx not 5xx
- bail!("entity was already deleted");
+ return Err(ErrorKind::InvalidEntityStateTransform(
+ "can't update an entity that doesn't exist yet".to_string()).into());
}
let rev_id = self.db_insert_rev(conn)?;
@@ -217,12 +214,12 @@ macro_rules! generic_db_delete {
) -> Result<Self::EditRow> {
let current: Self::IdentRow = $ident_table::table.find(ident.to_uuid()).first(conn)?;
if current.is_live != true {
- // TODO: what if isn't live? 4xx not 5xx
- bail!("can't delete an entity that doesn't exist yet");
+ return Err(ErrorKind::InvalidEntityStateTransform(
+ "can't update an entity that doesn't exist yet; delete edit object instead".to_string()).into());
}
if current.rev_id.is_none() {
- // TODO: what if it's already deleted? 4xx not 5xx
- bail!("entity was already deleted");
+ return Err(ErrorKind::InvalidEntityStateTransform(
+ "entity was already deleted".to_string()).into());
}
let edit: Self::EditRow = insert_into($edit_table::table)
.values((
@@ -292,8 +289,8 @@ macro_rules! generic_db_delete_edit {
.limit(1)
.get_results(conn)?;
if accepted_rows.len() != 0 {
- // TODO: should be a 4xx, not a 5xx
- bail!("attempted to delete an already accepted edit")
+ return Err(ErrorKind::EditgroupAlreadyAccepted(
+ "attempted to delete an already accepted edit".to_string()).into());
}
diesel::delete($edit_table::table.filter($edit_table::id.eq(edit_id))).execute(conn)?;
Ok(())