import java.lang.invoke.MethodHandles;
+import org.oransc.ric.portal.dashboard.exception.InvalidArgumentException;
import org.oransc.ric.portal.dashboard.exception.StatsManagerException;
import org.oransc.ric.portal.dashboard.exception.UnknownInstanceException;
import org.slf4j.Logger;
* @return A response entity with status code 502 and an unstructured message.
*/
@ExceptionHandler({ RestClientResponseException.class })
- public final ResponseEntity<String> handleProxyMethodException(Exception ex, WebRequest request) {
+ public final ResponseEntity<String> handleRestClientResponse(Exception ex, WebRequest request) {
// Capture the full stack trace in the log.
- log.error("handleProxyMethodException: request {}, exception {}", request.getDescription(false), ex);
+ if (log.isErrorEnabled())
+ log.error("handleRestClientResponse: request " + request.getDescription(false), ex);
if (ex instanceof HttpStatusCodeException) {
HttpStatusCodeException hsce = (HttpStatusCodeException) ex;
return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(hsce.getResponseBodyAsString());
}
/**
- * 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
* @return A response entity with status code 400 and an unstructured message.
*/
@ExceptionHandler({ UnknownInstanceException.class })
- public final ResponseEntity<String> handleUnknownInstanceException(Exception ex, WebRequest request) {
- log.warn("handleUnknownInstanceException: request {}, exception {}", request.getDescription(false),
- ex.toString());
+ public final ResponseEntity<String> handleUnknownInstance(Exception ex, WebRequest request) {
+ log.warn("handleUnknownInstance: request {}, exception {}", request.getDescription(false), ex.toString());
return ResponseEntity.badRequest().body(getShortExceptionMessage(ex));
}
/**
- * Logs a warning if a StatsManagerException is thrown.
+ * Logs the error and generates a response when a REST controller method takes
+ * an InvalidArgumentException, an invalid JSON was sent.
+ *
+ * @param ex
+ * The exception
+ * @param request
+ * The original request
+ * @return A response entity with status code 400 and an unstructured message.
+ */
+ @ExceptionHandler({ InvalidArgumentException.class })
+ public final ResponseEntity<String> handleInvalidArgument(Exception ex, WebRequest request) {
+ log.warn("handleInvalidArgument: request {}, exception {}", request.getDescription(false), ex.toString());
+ 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
* @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());
+ public final ResponseEntity<String> handleStatsManager(Exception ex, WebRequest request) {
+ log.warn("handleStatsManager: request {}, exception {}", request.getDescription(false), ex.toString());
return ResponseEntity.badRequest().body(getShortExceptionMessage(ex));
}