aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-11 15:30:30 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-11 15:30:30 -0800
commit3733c096fc2ff837ad28ed487ef9cccff4d1e1ed (patch)
treefdde450c2e078612742b2f3e7afd641e8ddab6c0 /rust
parent011deddfd53abf0eb13fbe292c1a175e1d8fdf7e (diff)
downloadfatcat-3733c096fc2ff837ad28ed487ef9cccff4d1e1ed.tar.gz
fatcat-3733c096fc2ff837ad28ed487ef9cccff4d1e1ed.zip
refactor out OtherBadRequest (just use BadRequest)
Diffstat (limited to 'rust')
-rw-r--r--rust/src/endpoints.rs9
-rw-r--r--rust/src/entity_crud.rs29
-rw-r--r--rust/src/errors.rs6
3 files changed, 19 insertions, 25 deletions
diff --git a/rust/src/endpoints.rs b/rust/src/endpoints.rs
index 8ed428a7..77f70ce0 100644
--- a/rust/src/endpoints.rs
+++ b/rust/src/endpoints.rs
@@ -707,7 +707,7 @@ impl Api for Server {
.transaction(|| {
if Some(editor_id.clone()) != editor.editor_id {
return Err(
- FatcatError::OtherBadRequest("editor_id doesn't match".to_string()).into(),
+ FatcatError::BadRequest("editor_id doesn't match".to_string()).into(),
);
}
let auth_context = self.auth_confectionary.require_auth(
@@ -972,10 +972,9 @@ impl Api for Server {
.transaction(|| {
let editgroup_id = FatcatId::from_str(&editgroup_id)?;
if Some(editgroup_id.to_string()) != editgroup.editgroup_id {
- return Err(FatcatError::OtherBadRequest(
- "editgroup_id doesn't match".to_string(),
- )
- .into());
+ return Err(
+ FatcatError::BadRequest("editgroup_id doesn't match".to_string()).into(),
+ );
}
let auth_context = self.auth_confectionary.require_auth(
&conn,
diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs
index b2ef6323..0b70d417 100644
--- a/rust/src/entity_crud.rs
+++ b/rust/src/entity_crud.rs
@@ -333,7 +333,7 @@ macro_rules! generic_db_create {
($ident_table: ident, $edit_table: ident) => {
fn db_create(&self, conn: &DbConn, edit_context: &EditContext) -> Result<Self::EditRow> {
if self.redirect.is_some() {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"can't create an entity that redirects from the start".to_string()).into());
}
let rev_id = self.db_insert_rev(conn)?;
@@ -361,7 +361,7 @@ macro_rules! generic_db_create_batch {
models: &[&Self],
) -> Result<Vec<Self::EditRow>> {
if models.iter().any(|m| m.redirect.is_some()) {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"can't create an entity that redirects from the start".to_string(),
)
.into());
@@ -420,14 +420,14 @@ macro_rules! generic_db_update {
if self.state.is_none() {
if Some(ident.to_string()) == self.redirect {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"tried to redirect entity to itself".to_string()).into());
}
// special case: redirect to another entity
if let Some(ref redirect_ident) = self.redirect {
let redirect_ident = FatcatId::from_str(&redirect_ident)?.to_uuid();
if Some(redirect_ident) == current.redirect_id {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"redundantly redirecting entity to it's current target currently isn't supported".to_string()).into());
}
// TODO: if we get a diesel not-found here, should be a special error response?
@@ -435,8 +435,7 @@ macro_rules! generic_db_update {
if target.is_live != true {
// there is no race condition on this check because WIP -> is_live=true is
// a one-way operation
- // XXX:
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"attempted to redirect to a WIP entity".to_string()).into());
}
// Note: there is a condition where the target is already a redirect, but we
@@ -458,7 +457,7 @@ macro_rules! generic_db_update {
if let Some(ref rev_id) = self.revision {
let rev_id = Uuid::from_str(&rev_id)?;
if Some(rev_id) == current.rev_id {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"reverted entity to it's current state; this isn't currently supported".to_string()).into());
}
let edit: Self::EditRow = insert_into($edit_table::table)
@@ -661,7 +660,7 @@ macro_rules! generic_db_accept_edits_batch {
.get_result(conn)?;
if forward_recursive_redirects != 0 {
// TODO: revert transaction?
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"one or more (forward) recurisve redirects".to_string(),
)
.into());
@@ -680,7 +679,7 @@ macro_rules! generic_db_accept_edits_batch {
.get_result(conn)?;
if backward_recursive_redirects != 0 {
// TODO: revert transaction?
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"one or more (backward) recurisve redirects".to_string(),
)
.into());
@@ -855,7 +854,7 @@ impl EntityCrud for ContainerEntity {
}
if models.iter().any(|m| m.name.is_none()) {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"name is required for all Container entities".to_string(),
)
.into());
@@ -966,7 +965,7 @@ impl EntityCrud for CreatorEntity {
}
if models.iter().any(|m| m.display_name.is_none()) {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"display_name is required for all Creator entities".to_string(),
)
.into());
@@ -1494,7 +1493,7 @@ impl EntityCrud for WebcaptureEntity {
}
}
if entity.timestamp.is_none() || entity.original_url.is_none() {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"timestamp and original_url are required for webcapture entities".to_string(),
)
.into());
@@ -1703,7 +1702,7 @@ impl EntityCrud for ReleaseEntity {
fn db_create(&self, conn: &DbConn, edit_context: &EditContext) -> Result<Self::EditRow> {
if self.redirect.is_some() {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"can't create an entity that redirects from the start".to_string(),
)
.into());
@@ -1721,7 +1720,7 @@ impl EntityCrud for ReleaseEntity {
// This isn't the generic implementation because we need to create Work entities for each
// of the release entities passed (at least in the common case)
if models.iter().any(|m| m.redirect.is_some()) {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"can't create an entity that redirects from the start".to_string(),
)
.into());
@@ -1948,7 +1947,7 @@ impl EntityCrud for ReleaseEntity {
}
if models.iter().any(|m| m.title.is_none()) {
- return Err(FatcatError::OtherBadRequest(
+ return Err(FatcatError::BadRequest(
"title is required for all Release entities".to_string(),
)
.into());
diff --git a/rust/src/errors.rs b/rust/src/errors.rs
index ec2b949b..08e79d51 100644
--- a/rust/src/errors.rs
+++ b/rust/src/errors.rs
@@ -93,11 +93,7 @@ pub enum FatcatError {
#[fail(display = "unexpected internal error: {}", _0)]
// Fmt, Io, Serde,
InternalError(String),
-
- // TODO: backwards compat; need to refactor out
- #[fail(display = "unexpected internal error: {}", _0)]
- OtherBadRequest(String), // NOTE: this enum is not exhaustive and shouldn't be matched over!
-}
+} // NOTE: this enum is not exhaustive and shouldn't be matched over!
impl Into<models::ErrorResponse> for FatcatError {
/// Format an error as an API response (ErrorResponse model, used by all HTTP 4xx and 5xx