X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dashboard%2Fwebapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fcontroller%2FCustomResponseEntityExceptionHandler.java;h=f4a873d8d5c1936c602d35341fe9b08877dd5a81;hb=848677173191182d46aa22ab83bee0de84999a81;hp=4c800d940e6feb413ecce98e5230eaf9b3548124;hpb=9a688995681b92344824c990bb1d838d3cc7cfaa;p=portal%2Fric-dashboard.git diff --git a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/CustomResponseEntityExceptionHandler.java b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/CustomResponseEntityExceptionHandler.java index 4c800d94..f4a873d8 100644 --- a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/CustomResponseEntityExceptionHandler.java +++ b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/CustomResponseEntityExceptionHandler.java @@ -21,6 +21,7 @@ package org.oransc.ric.portal.dashboard.controller; 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; @@ -81,9 +82,10 @@ public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptio * @return A response entity with status code 502 and an unstructured message. */ @ExceptionHandler({ RestClientResponseException.class }) - public final ResponseEntity handleProxyMethodException(Exception ex, WebRequest request) { + public final ResponseEntity 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()); @@ -103,9 +105,24 @@ public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptio * @return A response entity with status code 400 and an unstructured message. */ @ExceptionHandler({ UnknownInstanceException.class }) - public final ResponseEntity handleUnknownInstanceException(Exception ex, WebRequest request) { - log.warn("handleUnknownInstanceException: request {}, exception {}", request.getDescription(false), - ex.toString()); + public final ResponseEntity handleUnknownInstance(Exception ex, WebRequest request) { + log.warn("handleUnknownInstance: 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 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 handleInvalidArgument(Exception ex, WebRequest request) { + log.warn("handleInvalidArgument: request {}, exception {}", request.getDescription(false), ex.toString()); return ResponseEntity.badRequest().body(getShortExceptionMessage(ex)); } @@ -120,8 +137,8 @@ public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptio * @return A response entity with status code 400 and an unstructured message. */ @ExceptionHandler({ StatsManagerException.class }) - public final ResponseEntity handleStatsManagerException(Exception ex, WebRequest request) { - log.warn("handleStatsManagerException: request {}, exception {}", request.getDescription(false), ex.toString()); + public final ResponseEntity handleStatsManager(Exception ex, WebRequest request) { + log.warn("handleStatsManager: request {}, exception {}", request.getDescription(false), ex.toString()); return ResponseEntity.badRequest().body(getShortExceptionMessage(ex)); }