summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/src/api_server.rs8
-rw-r--r--rust/tests/test_api_server.rs39
2 files changed, 45 insertions, 2 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 24c62625..4c0f069e 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -57,6 +57,8 @@ macro_rules! wrap_entity_handlers {
$post_resp::CreatedEntity(edit),
Err(Error(ErrorKind::Diesel(e), _)) =>
$post_resp::BadRequest(ErrorResponse { message: e.to_string() }),
+ Err(Error(ErrorKind::Uuid(e), _)) =>
+ $post_resp::BadRequest(ErrorResponse { message: e.to_string() }),
Err(e) => $post_resp::GenericError(ErrorResponse { message: e.to_string() }),
};
Box::new(futures::done(Ok(ret)))
@@ -72,6 +74,8 @@ macro_rules! wrap_entity_handlers {
$post_batch_resp::CreatedEntities(edit),
Err(Error(ErrorKind::Diesel(e), _)) =>
$post_batch_resp::BadRequest(ErrorResponse { message: e.to_string() }),
+ Err(Error(ErrorKind::Uuid(e), _)) =>
+ $post_batch_resp::BadRequest(ErrorResponse { message: e.to_string() }),
Err(e) => $post_batch_resp::GenericError(ErrorResponse { message: e.to_string() }),
};
Box::new(futures::done(Ok(ret)))
@@ -661,9 +665,9 @@ impl Server {
Some(param) => param as i64,
};
- let work_id = uuid::Uuid::parse_str(&entity.work_id).expect("invalid UUID");
+ let work_id = uuid::Uuid::parse_str(&entity.work_id)?;
let container_id: Option<uuid::Uuid> = match entity.container_id {
- Some(id) => Some(uuid::Uuid::parse_str(&id).expect("invalid UUID")),
+ Some(id) => Some(uuid::Uuid::parse_str(&id)?),
None => None,
};
diff --git a/rust/tests/test_api_server.rs b/rust/tests/test_api_server.rs
index 86863f0b..7d63afe9 100644
--- a/rust/tests/test_api_server.rs
+++ b/rust/tests/test_api_server.rs
@@ -440,3 +440,42 @@ fn test_stats() {
Some("merged_editgroups"),
);
}
+
+#[test]
+fn test_400() {
+ let (headers, router, _conn) = setup();
+
+ check_response(
+ request::post(
+ "http://localhost:9411/v0/release",
+ headers,
+ r#"{"title": "secret paper",
+ "release_type": "journal-article",
+ "doi": "10.1234/abcde.781231231239",
+ "volume": "439",
+ "issue": "IV",
+ "pages": "1-399",
+ "work_id": "00000000-0000-0000-5555-00002",
+ "container_id": "00000000-0000-0000-1111-000000001",
+ "refs": [{
+ "index": 3,
+ "raw": "just a string"
+ },{
+ "raw": "just a string"
+ }],
+ "contribs": [{
+ "index": 1,
+ "raw": "textual description of contributor (aka, name)",
+ "creator_id": "00000000-0000-0000-2222-000000000001",
+ "contrib_type": "author"
+ },{
+ "raw": "shorter"
+ }],
+ "extra": { "source": "speculation" }
+ }"#,
+ &router,
+ ),
+ status::BadRequest,
+ None,
+ );
+}