Skip to content

Commit b77feb2

Browse files
committed
Return a more specific http status code on conflict.
1 parent a32ad4b commit b77feb2

16 files changed

Lines changed: 23 additions & 26 deletions

File tree

common/src/api/external/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,9 @@ impl From<Error> for HttpError {
420420

421421
Error::ObjectAlreadyExists { type_name: t, object_name: n } => {
422422
let message = format!("already exists: {} \"{}\"", t, n);
423-
HttpError::for_bad_request(
423+
HttpError::for_client_error(
424424
Some(String::from("ObjectAlreadyExists")),
425+
dropshot::ClientErrorStatusCode::CONFLICT,
425426
message,
426427
)
427428
}

nexus/tests/integration_tests/affinity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ async fn test_group_crud<T: AffinityGroupish>(client: &ClientTestContext) {
704704
// We can now create a group and observe it
705705
project_api.group_create(GROUP_NAME).await;
706706
let response = project_api
707-
.group_create_expect_error(GROUP_NAME, StatusCode::BAD_REQUEST)
707+
.group_create_expect_error(GROUP_NAME, StatusCode::CONFLICT)
708708
.await;
709709
assert_eq!(
710710
response.message,
@@ -726,7 +726,7 @@ async fn test_group_crud<T: AffinityGroupish>(client: &ClientTestContext) {
726726
.group_member_add_expect_error(
727727
GROUP_NAME,
728728
&instance_name,
729-
StatusCode::BAD_REQUEST,
729+
StatusCode::CONFLICT,
730730
)
731731
.await;
732732
assert_eq!(
@@ -858,7 +858,7 @@ async fn test_group_project_selector<T: AffinityGroupish>(
858858

859859
// We can only create a group within a project
860860
no_project_api
861-
.group_create_expect_error(GROUP_NAME, StatusCode::BAD_REQUEST)
861+
.group_create_expect_error(GROUP_NAME, StatusCode::CONFLICT)
862862
.await;
863863
let group = project_api.group_create(GROUP_NAME).await;
864864

nexus/tests/integration_tests/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ async fn test_projects_basic(cptestctx: &ControlPlaneTestContext) {
372372
let error = NexusRequest::new(
373373
RequestBuilder::new(client, Method::POST, &projects_url)
374374
.body(Some(&project_create))
375-
.expect_status(Some(StatusCode::BAD_REQUEST)),
375+
.expect_status(Some(StatusCode::CONFLICT)),
376376
)
377377
.authn_as(AuthnMode::PrivilegedUser)
378378
.execute()

nexus/tests/integration_tests/certificates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async fn cert_create_expect_error(
9797

9898
NexusRequest::expect_failure_with_body(
9999
client,
100-
StatusCode::BAD_REQUEST,
100+
StatusCode::CONFLICT,
101101
Method::POST,
102102
&url,
103103
&params,

nexus/tests/integration_tests/disks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ async fn test_disk_create_disk_that_already_exists_fails(
386386
let error: HttpErrorResponseBody = NexusRequest::new(
387387
RequestBuilder::new(client, Method::POST, &disks_url)
388388
.body(Some(&new_disk))
389-
.expect_status(Some(StatusCode::BAD_REQUEST)),
389+
.expect_status(Some(StatusCode::CONFLICT)),
390390
)
391391
.authn_as(AuthnMode::PrivilegedUser)
392392
.execute()

nexus/tests/integration_tests/external_ips.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ async fn test_floating_ip_create_name_in_use(
616616
},
617617
},
618618
}))
619-
.expect_status(Some(StatusCode::BAD_REQUEST)),
619+
.expect_status(Some(StatusCode::CONFLICT)),
620620
)
621621
.authn_as(AuthnMode::PrivilegedUser)
622622
.execute()

nexus/tests/integration_tests/external_subnets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ async fn external_subnet_create_name_conflict(
866866
client,
867867
&external_subnets_url(PROJECT_NAME),
868868
&create_params,
869-
StatusCode::BAD_REQUEST,
869+
StatusCode::CONFLICT,
870870
)
871871
.await;
872872
assert_eq!(error.error_code.as_deref(), Some("ObjectAlreadyExists"));

nexus/tests/integration_tests/images.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ async fn test_image_promotion(cptestctx: &ControlPlaneTestContext) {
414414

415415
NexusRequest::new(
416416
RequestBuilder::new(client, http::Method::POST, &promote_url)
417-
.expect_status(Some(StatusCode::BAD_REQUEST)),
417+
.expect_status(Some(StatusCode::CONFLICT)),
418418
)
419419
.authn_as(AuthnMode::PrivilegedUser)
420420
.execute()

nexus/tests/integration_tests/instances.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ async fn test_instances_create_reboot_halt(
390390
anti_affinity_groups: Vec::new(),
391391
multicast_groups: Vec::new(),
392392
}))
393-
.expect_status(Some(StatusCode::BAD_REQUEST)),
393+
.expect_status(Some(StatusCode::CONFLICT)),
394394
)
395395
.authn_as(AuthnMode::PrivilegedUser)
396396
.execute()

nexus/tests/integration_tests/ip_pools.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async fn test_ip_pool_basic_crud(cptestctx: &ControlPlaneTestContext) {
134134
},
135135
IpVersion::V4,
136136
),
137-
StatusCode::BAD_REQUEST,
137+
StatusCode::CONFLICT,
138138
)
139139
.await;
140140

@@ -508,7 +508,7 @@ async fn test_ip_pool_silo_link(cptestctx: &ControlPlaneTestContext) {
508508
client,
509509
"/v1/system/ip-pools/p0/silos",
510510
&params,
511-
StatusCode::BAD_REQUEST,
511+
StatusCode::CONFLICT,
512512
)
513513
.await;
514514
assert_eq!(error.error_code.unwrap(), "ObjectAlreadyExists");
@@ -560,13 +560,9 @@ async fn test_ip_pool_silo_link(cptestctx: &ControlPlaneTestContext) {
560560
// creating a third pool and trying to link it as default: true should fail
561561
create_ipv4_pool(client, "p2").await;
562562
let url = "/v1/system/ip-pools/p2/silos";
563-
let error = object_create_error(
564-
client,
565-
&url,
566-
&link_params,
567-
StatusCode::BAD_REQUEST,
568-
)
569-
.await;
563+
let error =
564+
object_create_error(client, &url, &link_params, StatusCode::CONFLICT)
565+
.await;
570566
assert_eq!(error.error_code.unwrap(), "ObjectAlreadyExists");
571567

572568
// unlink p1 from silo (doesn't matter that it's a default)

0 commit comments

Comments
 (0)