@@ -436,19 +436,21 @@ async fn instance_ensure_common(
436
436
{
437
437
let existing_properties = existing. properties ( ) ;
438
438
if existing_properties. id != properties. id {
439
- return Err ( HttpError :: for_status (
440
- Some ( format ! (
439
+ return Err ( HttpError :: for_client_error (
440
+ Some ( api:: ErrorCode :: AlreadyInitialized . to_string ( ) ) ,
441
+ http:: status:: StatusCode :: CONFLICT ,
442
+ format ! (
441
443
"Server already initialized with ID {}" ,
442
444
existing_properties. id
443
- ) ) ,
444
- http:: status:: StatusCode :: CONFLICT ,
445
+ ) ,
445
446
) ) ;
446
447
}
447
448
448
449
if * existing_properties != properties {
449
- return Err ( HttpError :: for_status (
450
- Some ( "Cannot update running server" . to_string ( ) ) ,
450
+ return Err ( HttpError :: for_client_error (
451
+ Some ( api :: ErrorCode :: AlreadyRunning . to_string ( ) ) ,
451
452
http:: status:: StatusCode :: CONFLICT ,
453
+ "Cannot update running server" . to_string ( ) ,
452
454
) ) ;
453
455
}
454
456
@@ -512,10 +514,11 @@ async fn instance_ensure_common(
512
514
vm_hdl. await . unwrap ( )
513
515
}
514
516
. map_err ( |e| {
515
- HttpError :: for_internal_error ( format ! (
516
- "failed to create instance: {}" ,
517
- e
518
- ) )
517
+ HttpError :: for_client_error (
518
+ Some ( api:: ErrorCode :: CreateFailed . to_string ( ) ) ,
519
+ http:: status:: StatusCode :: INTERNAL_SERVER_ERROR ,
520
+ format ! ( "failed to create instance: {e}" ) ,
521
+ )
519
522
} ) ?;
520
523
521
524
if let Some ( ramfb) = vm. framebuffer ( ) {
@@ -737,7 +740,7 @@ async fn instance_state_monitor(
737
740
// Inform the client of this condition so it doesn't wait forever.
738
741
state_watcher. changed ( ) . await . map_err ( |_| {
739
742
HttpError :: for_client_error (
740
- Some ( NO_INSTANCE . to_string ( ) ) ,
743
+ Some ( api :: ErrorCode :: NoInstance . to_string ( ) ) ,
741
744
http:: status:: StatusCode :: GONE ,
742
745
format ! (
743
746
"No instance present; will never reach generation {}" ,
@@ -1052,11 +1055,9 @@ pub fn api() -> ApiDescription<Arc<DropshotEndpointContext>> {
1052
1055
api
1053
1056
}
1054
1057
1055
- const NO_INSTANCE : & str = "NO_INSTANCE" ;
1056
-
1057
1058
fn not_created_error ( ) -> HttpError {
1058
1059
HttpError :: for_client_error (
1059
- Some ( NO_INSTANCE . to_string ( ) ) ,
1060
+ Some ( api :: ErrorCode :: NoInstance . to_string ( ) ) ,
1060
1061
http:: StatusCode :: FAILED_DEPENDENCY ,
1061
1062
"Server not initialized (no instance)" . to_string ( ) ,
1062
1063
)
0 commit comments