@@ -60,7 +60,8 @@ protected String parseRequestPayload(final HttpServerExchange e) {
6060      e .startBlocking ();
6161
6262    if  (!mustExecuteOnWorkerThread ())
63-       LogManager .instance ().log (this , Level .SEVERE , "Error: handler must return true at mustExecuteOnWorkerThread() to read payload from request" );
63+       LogManager .instance ()
64+           .log (this , Level .SEVERE , "Error: handler must return true at mustExecuteOnWorkerThread() to read payload from request" );
6465
6566    final  AtomicReference <String > result  = new  AtomicReference <>();
6667    e .getRequestReceiver ().receiveFullBytes (
@@ -90,7 +91,7 @@ public void handleRequest(final HttpServerExchange exchange) {
9091      final  HeaderValues  authorization  = exchange .getRequestHeaders ().get ("Authorization" );
9192      if  (isRequireAuthentication () && (authorization  == null  || authorization .isEmpty ())) {
9293        exchange .setStatusCode (401 );
93-         exchange .getResponseHeaders ().put (Headers .WWW_AUTHENTICATE ,"Basic" );
94+         exchange .getResponseHeaders ().put (Headers .WWW_AUTHENTICATE ,  "Basic" );
9495        sendErrorResponse (exchange , 401 , "" , null , null );
9596        return ;
9697      }
@@ -130,39 +131,56 @@ public void handleRequest(final HttpServerExchange exchange) {
130131
131132    } catch  (final  ServerSecurityException  e ) {
132133      // PASS SecurityException TO THE CLIENT 
133-       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Security error on command execution (%s)" , e , SecurityException .class .getSimpleName ());
134+       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Security error on command execution (%s): %s" ,
135+           SecurityException .class .getSimpleName (), e .getMessage ());
134136      sendErrorResponse (exchange , 403 , "Security error" , e , null );
135137    } catch  (final  ServerIsNotTheLeaderException  e ) {
136-       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s)" , e , getClass ().getSimpleName ());
138+       LogManager .instance ()
139+           .log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s): %s" , getClass ().getSimpleName (),
140+               e .getMessage ());
137141      sendErrorResponse (exchange , 400 , "Cannot execute command" , e , e .getLeaderAddress ());
138142    } catch  (final  NeedRetryException  e ) {
139-       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s)" , e , getClass ().getSimpleName ());
143+       LogManager .instance ()
144+           .log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s): %s" , getClass ().getSimpleName (),
145+               e .getMessage ());
140146      sendErrorResponse (exchange , 503 , "Cannot execute command" , e , null );
141147    } catch  (final  DuplicatedKeyException  e ) {
142-       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s)" , e , getClass ().getSimpleName ());
143-       sendErrorResponse (exchange , 503 , "Found duplicate key in index" , e , e .getIndexName () + "|"  + e .getKeys () + "|"  + e .getCurrentIndexedRID ());
148+       LogManager .instance ()
149+           .log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s): %s" , getClass ().getSimpleName (),
150+               e .getMessage ());
151+       sendErrorResponse (exchange , 503 , "Found duplicate key in index" , e ,
152+           e .getIndexName () + "|"  + e .getKeys () + "|"  + e .getCurrentIndexedRID ());
144153    } catch  (final  RecordNotFoundException  e ) {
145-       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s)" , e , getClass ().getSimpleName ());
154+       LogManager .instance ()
155+           .log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s): %s" , getClass ().getSimpleName (),
156+               e .getMessage ());
146157      sendErrorResponse (exchange , 404 , "Record not found" , e , null );
147158    } catch  (final  IllegalArgumentException  e ) {
148-       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s)" , e , getClass ().getSimpleName ());
159+       LogManager .instance ()
160+           .log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s): %s" , getClass ().getSimpleName (),
161+               e .getMessage ());
149162      sendErrorResponse (exchange , 400 , "Cannot execute command" , e , null );
150163    } catch  (final  CommandExecutionException  | CommandParsingException  e ) {
151164      Throwable  realException  = e ;
152165      if  (e .getCause () != null )
153166        realException  = e .getCause ();
154167
155-       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s)" , e , getClass ().getSimpleName ());
168+       LogManager .instance ()
169+           .log (this , getUserSevereErrorLogLevel (), "Error on command execution (%s): %s" , getClass ().getSimpleName (),
170+               e .getMessage ());
156171      sendErrorResponse (exchange , 500 , "Cannot execute command" , realException , null );
157172    } catch  (final  TransactionException  e ) {
158173      Throwable  realException  = e ;
159174      if  (e .getCause () != null )
160175        realException  = e .getCause ();
161176
162-       LogManager .instance ().log (this , getUserSevereErrorLogLevel (), "Error on transaction execution (%s)" , e , getClass ().getSimpleName ());
177+       LogManager .instance ()
178+           .log (this , getUserSevereErrorLogLevel (), "Error on transaction execution (%s): %s" , getClass ().getSimpleName (),
179+               e .getMessage ());
163180      sendErrorResponse (exchange , 500 , "Error on transaction commit" , realException , null );
164181    } catch  (final  Throwable  e ) {
165-       LogManager .instance ().log (this , getErrorLogLevel (), "Error on command execution (%s)" , e , getClass ().getSimpleName ());
182+       LogManager .instance ()
183+           .log (this , getErrorLogLevel (), "Error on command execution (%s): %s" , getClass ().getSimpleName (), e .getMessage ());
166184      sendErrorResponse (exchange , 500 , "Internal error" , e , null );
167185    } finally  {
168186      LogManager .instance ().setContext (null );
@@ -189,15 +207,17 @@ protected JSONObject createResult(final SecurityUser user, final Database databa
189207    final  JSONObject  json  = new  JSONObject ();
190208    if  (database  != null )
191209      json .setDateFormat (database .getSchema ().getDateTimeFormat ());
192-     json .put ("user" , user .getName ()).put ("version" , Constants .getVersion ()).put ("serverName" , httpServer .getServer ().getServerName ());
210+     json .put ("user" , user .getName ()).put ("version" , Constants .getVersion ())
211+         .put ("serverName" , httpServer .getServer ().getServerName ());
193212    return  json ;
194213  }
195214
196215  protected  String  decode (final  String  command ) {
197216    return  command .replace ("&" , " " ).replace ("<" , "<" ).replace (">" , ">" ).replace (""" , "\" " ).replace ("'" , "'" );
198217  }
199218
200-   protected  String  error2json (final  String  error , final  String  detail , final  Throwable  exception , final  String  exceptionArgs , final  String  help ) {
219+   protected  String  error2json (final  String  error , final  String  detail , final  Throwable  exception , final  String  exceptionArgs ,
220+       final  String  help ) {
201221    final  JSONObject  json  = new  JSONObject ();
202222    json .put ("error" , error );
203223    if  (detail  != null )
@@ -232,14 +252,19 @@ protected String getQueryParameter(final HttpServerExchange exchange, final Stri
232252  }
233253
234254  private  Level  getErrorLogLevel () {
235-     return  "development" .equals (httpServer .getServer ().getConfiguration ().getValueAsString (GlobalConfiguration .SERVER_MODE )) ? Level .SEVERE  : Level .FINE ;
255+     return  "development" .equals (httpServer .getServer ().getConfiguration ().getValueAsString (GlobalConfiguration .SERVER_MODE )) ?
256+         Level .SEVERE  :
257+         Level .FINE ;
236258  }
237259
238260  private  Level  getUserSevereErrorLogLevel () {
239-     return  "development" .equals (httpServer .getServer ().getConfiguration ().getValueAsString (GlobalConfiguration .SERVER_MODE )) ? Level .INFO  : Level .FINE ;
261+     return  "development" .equals (httpServer .getServer ().getConfiguration ().getValueAsString (GlobalConfiguration .SERVER_MODE )) ?
262+         Level .INFO  :
263+         Level .FINE ;
240264  }
241265
242-   private  void  sendErrorResponse (final  HttpServerExchange  exchange , final  int  code , final  String  errorMessage , final  Throwable  e , final  String  exceptionArgs ) {
266+   private  void  sendErrorResponse (final  HttpServerExchange  exchange , final  int  code , final  String  errorMessage , final  Throwable  e ,
267+       final  String  exceptionArgs ) {
243268    if  (!exchange .isResponseStarted ())
244269      exchange .setStatusCode (code );
245270    exchange .getResponseSender ().send (error2json (errorMessage , e  != null  ? e .getMessage () : "" , e , exceptionArgs , null ));
0 commit comments