@@ -75,8 +75,12 @@ public Mono<ServerResponse> startDatabase(ServerRequest req) {
7575 log .debug ("db launch mode:" + mode );
7676 var status = dbControlService .startDatabase ("start" , (String ) auth .getCredentials (),
7777 mode , replicateFrom , autoFetchWal );
78- if (ExecStatus .STATUS_FAILURE .equals (status .getStatus ())) {
79- return ServerResponse .badRequest ().body (BodyInserters .fromValue (new ErrorResult (status .toStatusString ())));
78+
79+ if (status == null || ExecStatus .STATUS_FAILURE .equals (status .getStatus ())) {
80+ var statusString = status != null ? status .toStatusString () : "status unknown" ;
81+ var errorMessage = String .format ("Failed to execute command. %s" , statusString );
82+ return ServerResponse .badRequest ()
83+ .body (BodyInserters .fromValue (new ErrorResult (errorMessage )));
8084 }
8185 return ServerResponse .ok ().build ();
8286 });
@@ -94,8 +98,10 @@ public Mono<ServerResponse> shutdownDatabase(ServerRequest req) {
9498 .map (SecurityContext ::getAuthentication )
9599 .flatMap (auth -> {
96100 var status = dbControlService .shutdownDatabase ("shutdown" , (String ) auth .getCredentials ());
97- if (ExecStatus .STATUS_FAILURE .equals (status .getStatus ())) {
98- return ServerResponse .badRequest ().body (BodyInserters .fromValue (new ErrorResult (status .toStatusString ())));
101+ if (status == null || ExecStatus .STATUS_FAILURE .equals (status .getStatus ())) {
102+ var statusString = status != null ? status .toStatusString () : "status unknown" ;
103+ var errorMessage = String .format ("Failed to execute command. %s" , statusString );
104+ return ServerResponse .badRequest ().body (BodyInserters .fromValue (new ErrorResult (errorMessage )));
99105 }
100106 return ServerResponse .ok ().build ();
101107 });
@@ -132,8 +138,11 @@ public Mono<ServerResponse> changeLaunchMode(ServerRequest req) {
132138 var status = dbControlService .changeDatabaseMode ("change_mode" ,
133139 (String ) auth .getCredentials (), mode ,
134140 from , autoFetchWal );
135- if (ExecStatus .STATUS_FAILURE .equals (status .getStatus ())) {
136- return ServerResponse .badRequest ().body (BodyInserters .fromValue (new ErrorResult (status .toStatusString ())));
141+ if (status == null || ExecStatus .STATUS_FAILURE .equals (status .getStatus ())) {
142+ var statusString = status != null ? status .toStatusString () : "status unknown" ;
143+ var errorMessage = String .format ("Failed to execute command. %s" , statusString );
144+ return ServerResponse .badRequest ()
145+ .body (BodyInserters .fromValue (new ErrorResult (errorMessage )));
137146 }
138147 return ServerResponse .ok ().build ();
139148 });
@@ -159,8 +168,12 @@ public Mono<ServerResponse> syncTransactionLog(ServerRequest req) {
159168 }
160169 var status = dbControlService .synchronizeTransactionLog ("sync_wal" ,
161170 (String ) auth .getCredentials (), fromHost );
162- if (ExecStatus .STATUS_FAILURE .equals (status .getStatus ())) {
163- return ServerResponse .badRequest ().body (BodyInserters .fromValue (new ErrorResult (status .toStatusString ())));
171+
172+ if (status == null || ExecStatus .STATUS_FAILURE .equals (status .getStatus ())) {
173+ var statusString = status != null ? status .toStatusString () : "status unknown" ;
174+ var errorMessage = String .format ("Failed to execute command. %s" , statusString );
175+ return ServerResponse .badRequest ()
176+ .body (BodyInserters .fromValue (new ErrorResult (errorMessage )));
164177 }
165178 return ServerResponse .ok ().build ();
166179 });
0 commit comments