CustomExceptionHandler { @ExceptionHandler(OpaClientException.class) public ResponseEntity<QueryResponse> handleOpaClientException(OpaClientException e) { ApiError apiError = new ApiError(500, e.getMessage()); QueryResponse queryResponse = new QueryResponse(); queryResponse.setErrors(List.of(apiError)); return new ResponseEntity<>(queryResponse, HttpStatus.INTERNAL_SERVER_ERROR); }  @ExceptionHandler(OpaClientException.class) ResponseEntity<QueryResponse> handleOpaClientException(OpaClientException e); @ExceptionHandler(PartialEvauationException.class) ResponseEntity<QueryResponse> handlePartialEvaluationException(PartialEvauationException e); @ExceptionHandler(ConversionFailedException.class) ResponseEntity<QueryResponse> handleConversionFailedException(ConversionFailedException e); @ExceptionHandler(IllegalArgumentException.class) ResponseEntity<QueryResponse> handleIllegalArgumentExceptionException(IllegalArgumentException e); @ExceptionHandler(Exception.class) ResponseEntity<QueryResponse> handleException(Exception e);  }
@Test void shouldHandleOpaClientException() { ResponseEntity<QueryResponse> result = target.handleOpaClientException(new OpaClientException("opaclientexception")); assertThat(result, is(notNullValue())); assertThat(result.getStatusCodeValue(), is(500)); }