@Test void willMapExecutionExceptions_WhenCauseIsAnIllegalArgumentException() { var exception = new ExecutionException("outer exception", new IllegalArgumentException("bad argument")); var expectedResponse = ApiErrorResponse.builder() .status(BAD_REQUEST) .message("bad argument") .timeStamp(Instant.now(clock)) .build(); assertEquals(new ResponseEntity<>(expectedResponse, new HttpHeaders(), BAD_REQUEST), controllerAdvice.handleExecutionException(exception)); }
@ExceptionHandler(ExecutionException.class) public ResponseEntity<Object> handleExecutionException(ExecutionException exception) { var cause = exception.getCause(); var message = cause instanceof IllegalArgumentException || cause instanceof IllegalStateException ? cause.getMessage() : exception.getMessage(); return new ResponseEntity<>(createResponseBody(message, BAD_REQUEST), new HttpHeaders(), BAD_REQUEST); }
ExceptionHandlingControllerAdvice extends ResponseEntityExceptionHandler { @ExceptionHandler(ExecutionException.class) public ResponseEntity<Object> handleExecutionException(ExecutionException exception) { var cause = exception.getCause(); var message = cause instanceof IllegalArgumentException || cause instanceof IllegalStateException ? cause.getMessage() : exception.getMessage(); return new ResponseEntity<>(createResponseBody(message, BAD_REQUEST), new HttpHeaders(), BAD_REQUEST); } }
ExceptionHandlingControllerAdvice extends ResponseEntityExceptionHandler { @ExceptionHandler(ExecutionException.class) public ResponseEntity<Object> handleExecutionException(ExecutionException exception) { var cause = exception.getCause(); var message = cause instanceof IllegalArgumentException || cause instanceof IllegalStateException ? cause.getMessage() : exception.getMessage(); return new ResponseEntity<>(createResponseBody(message, BAD_REQUEST), new HttpHeaders(), BAD_REQUEST); } ExceptionHandlingControllerAdvice(Clock clock); }
ExceptionHandlingControllerAdvice extends ResponseEntityExceptionHandler { @ExceptionHandler(ExecutionException.class) public ResponseEntity<Object> handleExecutionException(ExecutionException exception) { var cause = exception.getCause(); var message = cause instanceof IllegalArgumentException || cause instanceof IllegalStateException ? cause.getMessage() : exception.getMessage(); return new ResponseEntity<>(createResponseBody(message, BAD_REQUEST), new HttpHeaders(), BAD_REQUEST); } ExceptionHandlingControllerAdvice(Clock clock); @ExceptionHandler(AggregateNotFoundException.class) ResponseEntity<Object> handleNotFoundException(AggregateNotFoundException exception); @ExceptionHandler(RuntimeException.class) ResponseEntity<Object> handleRuntimeException(RuntimeException exception); @ExceptionHandler(ExecutionException.class) ResponseEntity<Object> handleExecutionException(ExecutionException exception); @ExceptionHandler(RemoteCommandExecutionException.class) ResponseEntity<Object> handleRemoteCommandExecutionException(RemoteCommandExecutionException exception); }
ExceptionHandlingControllerAdvice extends ResponseEntityExceptionHandler { @ExceptionHandler(ExecutionException.class) public ResponseEntity<Object> handleExecutionException(ExecutionException exception) { var cause = exception.getCause(); var message = cause instanceof IllegalArgumentException || cause instanceof IllegalStateException ? cause.getMessage() : exception.getMessage(); return new ResponseEntity<>(createResponseBody(message, BAD_REQUEST), new HttpHeaders(), BAD_REQUEST); } ExceptionHandlingControllerAdvice(Clock clock); @ExceptionHandler(AggregateNotFoundException.class) ResponseEntity<Object> handleNotFoundException(AggregateNotFoundException exception); @ExceptionHandler(RuntimeException.class) ResponseEntity<Object> handleRuntimeException(RuntimeException exception); @ExceptionHandler(ExecutionException.class) ResponseEntity<Object> handleExecutionException(ExecutionException exception); @ExceptionHandler(RemoteCommandExecutionException.class) ResponseEntity<Object> handleRemoteCommandExecutionException(RemoteCommandExecutionException exception);  }