@@ -571,19 +571,21 @@ async fn instance_ensure_common(
571
571
{
572
572
let existing_properties = existing. properties ( ) ;
573
573
if existing_properties. id != properties. id {
574
- return Err ( HttpError :: for_status (
575
- Some ( format ! (
574
+ return Err ( HttpError :: for_client_error (
575
+ Some ( api:: ErrorCode :: AlreadyInitialized . to_string ( ) ) ,
576
+ http:: status:: StatusCode :: CONFLICT ,
577
+ format ! (
576
578
"Server already initialized with ID {}" ,
577
579
existing_properties. id
578
- ) ) ,
579
- http:: status:: StatusCode :: CONFLICT ,
580
+ ) ,
580
581
) ) ;
581
582
}
582
583
583
584
if * existing_properties != properties {
584
- return Err ( HttpError :: for_status (
585
- Some ( "Cannot update running server" . to_string ( ) ) ,
585
+ return Err ( HttpError :: for_client_error (
586
+ Some ( api :: ErrorCode :: AlreadyRunning . to_string ( ) ) ,
586
587
http:: status:: StatusCode :: CONFLICT ,
588
+ "Cannot update running server" . to_string ( ) ,
587
589
) ) ;
588
590
}
589
591
@@ -653,10 +655,11 @@ async fn instance_ensure_common(
653
655
vm_hdl. await . unwrap ( )
654
656
}
655
657
. map_err ( |e| {
656
- HttpError :: for_internal_error ( format ! (
657
- "failed to create instance: {}" ,
658
- e
659
- ) )
658
+ HttpError :: for_client_error (
659
+ Some ( api:: ErrorCode :: CreateFailed . to_string ( ) ) ,
660
+ http:: status:: StatusCode :: INTERNAL_SERVER_ERROR ,
661
+ format ! ( "failed to create instance: {e}" ) ,
662
+ )
660
663
} ) ?;
661
664
662
665
if let Some ( ramfb) = vm. framebuffer ( ) {
@@ -875,7 +878,7 @@ async fn instance_state_monitor(
875
878
// Inform the client of this condition so it doesn't wait forever.
876
879
state_watcher. changed ( ) . await . map_err ( |_| {
877
880
HttpError :: for_client_error (
878
- Some ( NO_INSTANCE . to_string ( ) ) ,
881
+ Some ( api :: ErrorCode :: NoInstance . to_string ( ) ) ,
879
882
http:: status:: StatusCode :: GONE ,
880
883
format ! (
881
884
"No instance present; will never reach generation {}" ,
@@ -1193,11 +1196,9 @@ pub fn api() -> ApiDescription<Arc<DropshotEndpointContext>> {
1193
1196
api
1194
1197
}
1195
1198
1196
- const NO_INSTANCE : & str = "NO_INSTANCE" ;
1197
-
1198
1199
fn not_created_error ( ) -> HttpError {
1199
1200
HttpError :: for_client_error (
1200
- Some ( NO_INSTANCE . to_string ( ) ) ,
1201
+ Some ( api :: ErrorCode :: NoInstance . to_string ( ) ) ,
1201
1202
http:: StatusCode :: FAILED_DEPENDENCY ,
1202
1203
"Server not initialized (no instance)" . to_string ( ) ,
1203
1204
)
0 commit comments