@Test void willMapRemoteCommandExecutionExceptionWithNestedException() { var exception = new RemoteCommandExecutionException(new Exception("inner exception")); var expectedResponse = ApiErrorResponse.builder() .status(BAD_REQUEST) .message("inner exception") .timeStamp(Instant.now(clock)) .build(); assertEquals(new ResponseEntity<>(expectedResponse, new HttpHeaders(), BAD_REQUEST), controllerAdvice.handleRemoteCommandExecutionException(exception)); }
@ExceptionHandler(RemoteCommandExecutionException.class) public ResponseEntity<Object> handleRemoteCommandExecutionException(RemoteCommandExecutionException exception) { var cause = exception.getCause(); if (cause instanceof ExecutionException) { return handleExecutionException((ExecutionException)cause); } return new ResponseEntity<>(createResponseBody(cause.getMessage(), BAD_REQUEST), new HttpHeaders(), BAD_REQUEST); }
ExceptionHandlingControllerAdvice extends ResponseEntityExceptionHandler { @ExceptionHandler(RemoteCommandExecutionException.class) public ResponseEntity<Object> handleRemoteCommandExecutionException(RemoteCommandExecutionException exception) { var cause = exception.getCause(); if (cause instanceof ExecutionException) { return handleExecutionException((ExecutionException)cause); } return new ResponseEntity<>(createResponseBody(cause.getMessage(), BAD_REQUEST), new HttpHeaders(), BAD_REQUEST); } }
ExceptionHandlingControllerAdvice extends ResponseEntityExceptionHandler { @ExceptionHandler(RemoteCommandExecutionException.class) public ResponseEntity<Object> handleRemoteCommandExecutionException(RemoteCommandExecutionException exception) { var cause = exception.getCause(); if (cause instanceof ExecutionException) { return handleExecutionException((ExecutionException)cause); } return new ResponseEntity<>(createResponseBody(cause.getMessage(), BAD_REQUEST), new HttpHeaders(), BAD_REQUEST); } ExceptionHandlingControllerAdvice(Clock clock); }
ExceptionHandlingControllerAdvice extends ResponseEntityExceptionHandler { @ExceptionHandler(RemoteCommandExecutionException.class) public ResponseEntity<Object> handleRemoteCommandExecutionException(RemoteCommandExecutionException exception) { var cause = exception.getCause(); if (cause instanceof ExecutionException) { return handleExecutionException((ExecutionException)cause); } return new ResponseEntity<>(createResponseBody(cause.getMessage(), 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(RemoteCommandExecutionException.class) public ResponseEntity<Object> handleRemoteCommandExecutionException(RemoteCommandExecutionException exception) { var cause = exception.getCause(); if (cause instanceof ExecutionException) { return handleExecutionException((ExecutionException)cause); } return new ResponseEntity<>(createResponseBody(cause.getMessage(), 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);  }