Merge "Add tests to improve code-coverage stats in Sonar"
[portal/ric-dashboard.git] / dashboard / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / controller / CustomResponseEntityExceptionHandler.java
index e75dfcb..4c800d9 100644 (file)
@@ -21,6 +21,7 @@ package org.oransc.ric.portal.dashboard.controller;
 
 import java.lang.invoke.MethodHandles;
 
+import org.oransc.ric.portal.dashboard.exception.StatsManagerException;
 import org.oransc.ric.portal.dashboard.exception.UnknownInstanceException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -92,7 +93,8 @@ public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptio
        }
 
        /**
-        * Logs a warning if an invalid RIC instance key is used.
+        * Logs the error and generates a response when a REST controller method takes
+        * an UnknownInstanceException, an invalid RIC instance key was used.
         * 
         * @param ex
         *                    The exception
@@ -107,4 +109,20 @@ public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptio
                return ResponseEntity.badRequest().body(getShortExceptionMessage(ex));
        }
 
+       /**
+        * Logs the error and generates a response when a REST controller method takes
+        * an StatsManagerException.
+        * 
+        * @param ex
+        *                    The exception
+        * @param request
+        *                    The original request
+        * @return A response entity with status code 400 and an unstructured message.
+        */
+       @ExceptionHandler({ StatsManagerException.class })
+       public final ResponseEntity<String> handleStatsManagerException(Exception ex, WebRequest request) {
+               log.warn("handleStatsManagerException: request {}, exception {}", request.getDescription(false), ex.toString());
+               return ResponseEntity.badRequest().body(getShortExceptionMessage(ex));
+       }
+
 }