File tree Expand file tree Collapse file tree 2 files changed +8
-23
lines changed
main/java/com/influxdb/v3/client/internal
test/java/com/influxdb/v3/client/internal Expand file tree Collapse file tree 2 files changed +8
-23
lines changed Original file line number Diff line number Diff line change 3636import java .util .ArrayList ;
3737import java .util .List ;
3838import java .util .Map ;
39+ import java .util .Optional ;
3940import java .util .stream .Stream ;
4041import javax .annotation .Nonnull ;
4142import javax .annotation .Nullable ;
@@ -159,17 +160,13 @@ public String getServerVersion() throws InfluxDBApiException {
159160 return influxdbVersion ;
160161 }
161162
162- private String extractServerVersion (final HttpResponse <String > response ) {
163- return response .headers ()
164- .firstValue ("x-influxdb-version" )
165- .orElseGet (() -> {
166- try {
167- JsonNode jsonNode = objectMapper .readTree (response .body ());
168- return jsonNode .get ("version" ).asText ();
169- } catch (JsonProcessingException e ) {
170- throw new InfluxDBApiException (e );
171- }
172- });
163+ private String extractServerVersion (final HttpResponse <String > response ) throws JsonProcessingException {
164+ String version = response .headers ().firstValue ("X-Influxdb-Version" ).orElse (null );
165+ if (version == null ) {
166+ JsonNode jsonNode = objectMapper .readTree (response .body ());
167+ version = Optional .ofNullable (jsonNode .get ("version" )).map (JsonNode ::asText ).orElse (null );
168+ }
169+ return version ;
173170 }
174171
175172 void request (@ Nonnull final String path ,
Original file line number Diff line number Diff line change @@ -502,16 +502,4 @@ public void getServerVersionV3Successful() throws Exception {
502502
503503 Assertions .assertThat (version ).isEqualTo (influxDBVersion );
504504 }
505-
506- @ Test
507- public void getServerVersionThrowsExceptionOnFailure () {
508- mockServer .enqueue (createResponse (500 ).setBody ("{\" message\" :\" internal server error\" }" ));
509-
510- restClient = new RestClient (new ClientConfig .Builder ()
511- .host (baseURL )
512- .build ());
513-
514- Assertions .assertThatThrownBy (() -> restClient .getServerVersion ())
515- .isInstanceOf (InfluxDBApiException .class );
516- }
517505}
You can’t perform that action at this time.
0 commit comments