### Question:
InfluxException extends RuntimeException { @Nonnull public JSONObject errorBody() { return errorBody; } InfluxException(@Nullable final String message);  InfluxException(@Nullable final Throwable cause);  InfluxException(@Nullable final Response<?> cause); @Override String getMessage(); int reference(); int status(); @Nonnull JSONObject errorBody();  }### Answer:
@Test void errorBody() { Assertions .assertThatThrownBy(() -> { Response<Object> response = errorResponse("Wrong query", 501, 15, "{\"error\": \"error-body\"}"); throw new InfluxException(new HttpException(response)); }) .matches((Predicate<Throwable>) throwable -> ((InfluxException) throwable).errorBody().toString().equals("{\"error\":\"error-body\"}")); }
@Test void errorBodyReadAgain() { Assertions .assertThatThrownBy(() -> { Response<Object> response = errorResponse("Wrong query", 501, 15, "{\"error\": \"error-body\"}"); throw new InfluxException(new HttpException(response)); }) .matches((Predicate<Throwable>) throwable -> { JSONObject errorBody1 = ((InfluxException) throwable).errorBody(); JSONObject errorBody2 = ((InfluxException) throwable).errorBody(); return errorBody1.toString().equals("{\"error\":\"error-body\"}") && errorBody1.equals(errorBody2); }); }
@Test void errorBodyResponseNull() { Assertions .assertThatThrownBy(() -> { throw new InfluxException(new IllegalStateException("unExpectedError")); }) .matches((Predicate<Throwable>) throwable -> ((InfluxException) throwable).errorBody().toString().equals("{}")); }
@Test void errorBodyResponseWithoutBody() { Assertions .assertThatThrownBy(() -> { throw new InfluxException(new HttpException(errorResponse("Wrong query"))); }) .matches((Predicate<Throwable>) throwable -> ((InfluxException) throwable).errorBody().toString().equals("{}")); }