@@ -117,27 +117,35 @@ public void apply(final Javalin javalin) {
117117 // Default exception handlers for common endpoint exceptions
118118 javalin .exception (NoSuchWorkspaceException .class ,
119119 (ex , ctx ) -> ctx .status (404 ).json (new FormattedError (ex )));
120- javalin .exception (IOException .class ,
121- (ex , ctx ) -> ctx .status (500 ).json (new FormattedError (ex )));
122- javalin .exception (SQLException .class ,
123- (ex , ctx ) -> ctx .status (500 ).json (new FormattedError (ex )));
120+ javalin .exception (IOException .class , (ex , ctx ) -> {
121+ final var fe = new FormattedError (ex );
122+ logger .warn ("IO Exception: {}" , fe );
123+ ctx .status (500 ).json (fe );
124+ });
125+ javalin .exception (SQLException .class , (ex , ctx ) -> {
126+ final var fe = new FormattedError (ex );
127+ logger .warn ("SQL Exception: {}" , fe );
128+ ctx .status (500 ).json (fe );
129+ });
124130 javalin .exception (UnauthorizedResponse .class , (ex , ctx ) -> {
125131 final var message = ex .getMessage () != null ? ex .getMessage () : "Unauthorized" ;
126132 logger .warn ("401 Unauthorized: {}" , message );
127133 ctx .status (401 ).json (new FormattedError (ex ));
128134 });
129135 javalin .exception (NumberFormatException .class ,
130136 (ex , ctx ) -> ctx .status (400 ).json (new FormattedError (ex )));
131- javalin .exception (SecurityException .class ,
132- (ex , ctx ) -> ctx .status (500 ).json (new FormattedError (ex )));
133- javalin .exception (HttpResponseException .class ,
134- (ex , ctx ) ->
135- ctx .status (ex .getStatus ()).json (new FormattedError ("HTTP_RESPONSE_EXCEPTION" , ex )));
137+ javalin .exception (SecurityException .class , (ex , ctx ) -> {
138+ final var fe = new FormattedError (ex );
139+ logger .warn ("Security Exception: {}" , fe );
140+ ctx .status (500 ).json (fe );
141+ });
142+ javalin .exception (HttpResponseException .class , (ex , ctx ) -> ctx .status (ex .getStatus ()).json (new FormattedError ("HTTP_RESPONSE_EXCEPTION" , ex )));
136143 javalin .exception (Exception .class , (ex , ctx ) -> {
137144 // Catch-all for unexpected issues
138- logger .error ("Unexpected error processing workspace request" , ex );
139145 final var message = ex .getMessage () != null ? ex .getMessage () : "Unknown error." ;
140- ctx .status (500 ).json (new FormattedError ("UNKNOWN_ERROR" , message , ex ));
146+ final var fe = new FormattedError ("UNKNOWN_ERROR" , message , ex );
147+ logger .error ("Unexpected error processing workspace request {}" , fe );
148+ ctx .status (500 ).json (fe );
141149 });
142150 }
143151
@@ -194,12 +202,16 @@ private boolean checkPermissions(Context context, int workspaceId, WorkspaceActi
194202 context .status (403 ).json (new FormattedError (ue ));
195203 return false ;
196204 } catch (IOException ioe ) {
197- context .status (500 ).json (new FormattedError (ioe , "Could not check permissions." ));
205+ final var fe = new FormattedError (ioe , "Could not check permissions." );
206+ logger .warn ("IO Exception: {}" , fe );
207+ context .status (500 ).json (fe );
198208 return false ;
199209 } catch (PermissionsServiceException pse ) {
210+ final var fe = new FormattedError (pse , "Could not check permissions." );
211+ logger .warn ("Permissions Service Exception: {}" , fe );
200212 context .status (500 ).json (new FormattedError (pse , "Could not check permissions." ));
201213 return false ;
202- }catch (gov .nasa .jpl .aerie .permissions .exceptions .NoSuchWorkspaceException nsw ) {
214+ } catch (gov .nasa .jpl .aerie .permissions .exceptions .NoSuchWorkspaceException nsw ) {
203215 context .status (404 ).json (new FormattedError (nsw , "Could not check permissions on Workspace %d." .formatted (nsw .id .id ())));
204216 return false ;
205217 }
@@ -216,10 +228,14 @@ private void createWorkspace(Context context) {
216228 context .status (403 ).json (new FormattedError (ue ));
217229 return ;
218230 } catch (IOException ioe ) {
219- context .status (500 ).json (new FormattedError (ioe , "Could not create workspace." ));
231+ final var fe = new FormattedError (ioe , "Could not create workspace." );
232+ logger .warn ("IO Exception: {}" , fe );
233+ context .status (500 ).json (fe );
220234 return ;
221235 } catch (PermissionsServiceException pse ) {
222- context .status (500 ).json (new FormattedError (pse , "Could not create workspace." ));
236+ final var fe = new FormattedError (pse , "Could not create workspace." );
237+ logger .warn ("Permissions Service Exception: {}" , fe );
238+ context .status (500 ).json (fe );
223239 return ;
224240 }
225241
@@ -288,6 +304,14 @@ private void createWorkspace(Context context) {
288304 if (workspaceId .isPresent ()) {
289305 context .status (200 ).result (workspaceId .get ().toString ());
290306 } else {
307+ logger .warn (
308+ """
309+ Create Workspace failed for inputs:
310+ \t Location: {},
311+ \t Name: {},
312+ \t Parcel ID: {},
313+ \t User: {} (active role: {})
314+ """ , workspaceLocation , workspaceName , parcelId , user .userId (), user .activeRole ());
291315 context .status (500 ).json (new FormattedError ("Unable to create workspace." ));
292316 }
293317 }
@@ -304,12 +328,15 @@ private void deleteWorkspace(Context context) {
304328 if (workspaceService .deleteWorkspace (workspaceId )) {
305329 context .status (200 ).result ("Workspace deleted." );
306330 } else {
331+ logger .warn (errorMsg );
307332 context .status (500 ).json (new FormattedError (errorMsg ));
308333 }
309334 } catch (NoSuchWorkspaceException ex ) {
310335 context .status (404 ).json (new FormattedError (ex , errorMsg ));
311336 } catch (SQLException e ) {
312- context .status (500 ).json (new FormattedError (e , errorMsg ));
337+ final var fe = new FormattedError (e , errorMsg );
338+ logger .warn ("SQL Exception: {}" , fe );
339+ context .status (500 ).json (fe );
313340 }
314341 }
315342
@@ -347,9 +374,13 @@ private void listContents(Context context) {
347374 }
348375 context .status (200 ).json (fileTree .toJson ().toString ());
349376 } catch (IOException ioe ) {
350- context .status (500 ).json (new FormattedError (ioe ));
377+ final var fe = new FormattedError (ioe );
378+ logger .warn ("IO Exception: {}" , fe );
379+ context .status (500 ).json (fe );
351380 } catch (SQLException se ) {
352- context .status (500 ).json (new FormattedError (se ));
381+ final var fe = new FormattedError (se );
382+ logger .warn ("SQL Exception: {}" , fe );
383+ context .status (500 ).json (fe );
353384 } catch (NoSuchWorkspaceException ex ) {
354385 context .status (404 ).json (new FormattedError (ex ));
355386 }
@@ -378,9 +409,13 @@ private void get(Context context) throws NoSuchWorkspaceException {
378409 context .header ("Content-Disposition" , "attachment; filename=\" " + pathInfo .fileName () + "\" " );
379410 context .status (200 ).result (inputStream );
380411 } catch (IOException ioe ) {
381- context .status (500 ).json (new FormattedError (ioe , "Could not load file " + pathInfo .fileName ()));
412+ final var fe = new FormattedError (ioe , "Could not load file " + pathInfo .fileName ());
413+ logger .warn ("IO Exception: {}" , fe );
414+ context .status (500 ).json (fe );
382415 } catch (SQLException se ) {
383- context .status (500 ).json (new FormattedError (se , "Could not load file " + pathInfo .fileName ()));
416+ final var fe = new FormattedError (se , "Could not load file " + pathInfo .fileName ());
417+ logger .warn ("SQL Exception: {}" , fe );
418+ context .status (500 ).json (fe );
384419 }
385420 }
386421 }
@@ -432,9 +467,11 @@ private void put(Context context) throws NoSuchWorkspaceException, IOException {
432467 if (workspaceService .saveFile (pathInfo .workspaceId , pathInfo .filePath , file )) {
433468 context .status (200 ).result ("File " + pathInfo .fileName () + " uploaded to " + pathInfo .filePath );
434469 } else {
470+ logger .warn ("Save File failed for path {}" , pathInfo .filePath );
435471 context .status (500 ).json (new FormattedError ("Could not save file." ));
436472 }
437473 } catch (WorkspaceFileOpException wfe ) {
474+ logger .warn ("Save File failed for path {}" , pathInfo .filePath );
438475 context .status (500 ).json (new FormattedError (wfe , "Could not save file." ));
439476 }
440477 } else if (type == ItemType .directory ) {
@@ -448,9 +485,11 @@ private void put(Context context) throws NoSuchWorkspaceException, IOException {
448485 if (workspaceService .createDirectory (pathInfo .workspaceId , pathInfo .filePath )) {
449486 context .status (200 ).result ("Directory created." );
450487 } else {
488+ logger .warn ("Create Directory failed for path {}" , pathInfo .filePath );
451489 context .status (500 ).json (new FormattedError ("Could not create directory." ));
452490 }
453491 } catch (WorkspaceFileOpException wfe ) {
492+ logger .warn ("Create Directory failed for path {}" , pathInfo .filePath );
454493 context .status (500 ).json (new FormattedError (wfe , "Could not create directory." ));
455494 }
456495 } else {
@@ -655,17 +694,21 @@ private void delete(Context context) throws NoSuchWorkspaceException, IOExceptio
655694 if (workspaceService .deleteDirectory (pathInfo .workspaceId , pathInfo .filePath )) {
656695 context .status (200 ).result ("Directory deleted." );
657696 } else {
697+ logger .warn ("Delete Directory failed for path {}" , pathInfo .filePath );
658698 context .status (500 ).json (new FormattedError (errorMsg ));
659699 }
660700 } else {
661701 try {
662702 if (workspaceService .deleteFile (pathInfo .workspaceId , pathInfo .filePath )) {
663703 context .status (200 ).result ("File deleted." );
664704 } else {
705+ logger .warn ("Delete File failed for path {}" , pathInfo .filePath );
665706 context .status (500 ).json (new FormattedError (errorMsg ));
666707 }
667708 } catch (SQLException se ) {
668- context .status (500 ).json (new FormattedError (se ));
709+ final var fe = new FormattedError (se );
710+ logger .warn ("SQL Exception: {}" , fe );
711+ context .status (500 ).json (fe );
669712 }
670713 }
671714 }
@@ -809,15 +852,20 @@ public void bulkUpload(Context context) throws NoSuchWorkspaceException {
809852 response .add ("status" , 200 )
810853 .add ("response" , "File " + item .path ().getFileName () + " uploaded to " + item .path ());
811854 } else {
855+ logger .warn ("BULK UPLOAD: Could not save file" );
812856 response .add ("status" , 500 )
813857 .add ("response" , new FormattedError ("Could not save file." ).toJson ());
814858 }
815859 } catch (IOException ioe ) {
860+ final var fe = new FormattedError (ioe , "Could not save file." );
861+ logger .warn ("BULK UPLOAD: IOException: {}" , fe );
816862 response .add ("status" , 500 )
817- .add ("response" , new FormattedError ( ioe , "Could not save file." ) .toJson ());
863+ .add ("response" , fe .toJson ());
818864 } catch (WorkspaceFileOpException wfe ) {
865+ final var fe = new FormattedError (wfe , "Could not save file." );
866+ logger .warn ("BULK UPLOAD: WorkspaceFileOpException: {}" , fe );
819867 response .add ("status" , 500 )
820- .add ("response" , new FormattedError ( wfe , "Could not create directory." ) .toJson ());
868+ .add ("response" , fe .toJson ());
821869 }
822870 } else if (item .uploadType () == ItemType .directory ) {
823871 // Create directory
@@ -826,17 +874,23 @@ public void bulkUpload(Context context) throws NoSuchWorkspaceException {
826874 response .add ("status" , 200 )
827875 .add ("response" , "Directory created." );
828876 } else {
877+ logger .warn ("BULK UPLOAD: Could not create directory" );
829878 response .add ("status" , 500 )
830879 .add ("response" , new FormattedError ("Could not create directory." ).toJson ());
831880 }
832881 } catch (IOException ioe ) {
882+ final var fe = new FormattedError (ioe , "Could not create directory." );
883+ logger .warn ("BULK UPLOAD: IOException: {}" , fe );
833884 response .add ("status" , 500 )
834- .add ("response" , new FormattedError ( ioe , "Could not create directory." ) .toJson ());
885+ .add ("response" , fe .toJson ());
835886 } catch (WorkspaceFileOpException wfe ) {
887+ final var fe = new FormattedError (wfe , "Could not create directory." );
888+ logger .warn ("BULK UPLOAD: WorkspaceFileOpException: {}" , fe );
836889 response .add ("status" , 500 )
837- .add ("response" , new FormattedError ( wfe , "Could not create directory." ) .toJson ());
890+ .add ("response" , fe .toJson ());
838891 }
839892 } else {
893+ logger .debug ("BULK UPLOAD: Unsupported item upload type: {}" , item .uploadType ());
840894 response .add ("status" , 501 )
841895 .add ("response" , new FormattedError ("Unsupported item upload type: " +item .uploadType ().name ()).toJson ());
842896 }
@@ -1091,6 +1145,7 @@ public void bulkDelete(Context context) throws NoSuchWorkspaceException {
10911145 response .add ("status" , 200 )
10921146 .add ("response" , "Directory deleted." );
10931147 } else {
1148+ logger .warn ("BULK DELETE: {}" , errorMsg );
10941149 response .add ("status" , 500 )
10951150 .add ("response" , new FormattedError (errorMsg ).toJson ());
10961151 }
@@ -1099,16 +1154,21 @@ public void bulkDelete(Context context) throws NoSuchWorkspaceException {
10991154 response .add ("status" , 200 )
11001155 .add ("response" , "File deleted." );
11011156 } else {
1157+ logger .warn ("BULK DELETE: {}" , errorMsg );
11021158 response .add ("status" , 500 )
11031159 .add ("response" , new FormattedError (errorMsg ).toJson ());
11041160 }
11051161 }
11061162 } catch (IOException ioe ) {
1163+ final var fe = new FormattedError (ioe , errorMsg );
1164+ logger .warn ("BULK DELETE: IOException: {}" , fe );
11071165 response .add ("status" , 500 )
1108- .add ("response" , new FormattedError ( ioe , errorMsg ) .toJson ());
1166+ .add ("response" , fe .toJson ());
11091167 } catch (SQLException se ) {
1168+ final var fe = new FormattedError (se , errorMsg );
1169+ logger .warn ("BULK DELETE: SQLException: {}" , fe );
11101170 response .add ("status" , 500 )
1111- .add ("response" , new FormattedError ( se , errorMsg ) .toJson ());
1171+ .add ("response" , fe .toJson ());
11121172 }
11131173
11141174 // Add response to array
0 commit comments