- public final ResponseEntity<ErrorTransport> handleUnknownInstanceException(Exception ex, WebRequest request) {
- log.warn("handleUnknownInstanceException: request {}, exception {}", request.getDescription(false),
- ex.toString());
- return new ResponseEntity<>(new ErrorTransport(400, ex), HttpStatus.BAD_REQUEST);
+ 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 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
+ * @param request
+ * The original request
+ * @return A response entity with status code 400 and an unstructured message.
+ */
+ @ExceptionHandler({ StatsManagerException.class })
+ 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));