|
3 | 3 |
|
4 | 4 | import com.squareup.moshi.JsonAdapter;
|
5 | 5 | import com.squareup.moshi.Moshi;
|
6 |
| -import okhttp3.Headers; |
7 |
| -import okhttp3.MediaType; |
8 |
| -import okhttp3.OkHttpClient; |
9 |
| -import okhttp3.Request; |
10 |
| -import okhttp3.RequestBody; |
11 |
| -import okhttp3.ResponseBody; |
| 6 | +import okhttp3.*; |
12 | 7 | import okhttp3.logging.HttpLoggingInterceptor;
|
13 | 8 | import okhttp3.logging.HttpLoggingInterceptor.Level;
|
14 | 9 | import okio.BufferedSource;
|
15 |
| - |
16 | 10 | import org.influxdb.BatchOptions;
|
17 | 11 | import org.influxdb.InfluxDB;
|
18 | 12 | import org.influxdb.InfluxDBException;
|
19 | 13 | import org.influxdb.InfluxDBIOException;
|
20 |
| -import org.influxdb.dto.BatchPoints; |
21 |
| -import org.influxdb.dto.BoundParameterQuery; |
22 |
| -import org.influxdb.dto.Point; |
23 |
| -import org.influxdb.dto.Pong; |
24 |
| -import org.influxdb.dto.Query; |
25 |
| -import org.influxdb.dto.QueryResult; |
| 14 | +import org.influxdb.dto.*; |
26 | 15 | import org.influxdb.impl.BatchProcessor.HttpBatchEntry;
|
27 | 16 | import org.influxdb.impl.BatchProcessor.UdpBatchEntry;
|
28 | 17 | import org.influxdb.msgpack.MessagePackConverterFactory;
|
29 | 18 | import org.influxdb.msgpack.MessagePackTraverser;
|
30 |
| - |
31 | 19 | import retrofit2.Call;
|
32 | 20 | import retrofit2.Callback;
|
33 | 21 | import retrofit2.Converter.Factory;
|
|
38 | 26 | import java.io.EOFException;
|
39 | 27 | import java.io.IOException;
|
40 | 28 | import java.io.InputStream;
|
41 |
| -import java.net.DatagramPacket; |
42 |
| -import java.net.DatagramSocket; |
43 |
| -import java.net.InetAddress; |
44 |
| -import java.net.InetSocketAddress; |
45 |
| -import java.net.SocketException; |
46 |
| -import java.net.URI; |
47 |
| -import java.net.URISyntaxException; |
48 |
| -import java.net.UnknownHostException; |
| 29 | +import java.net.*; |
49 | 30 | import java.nio.charset.StandardCharsets;
|
50 | 31 | import java.util.ArrayList;
|
51 |
| -import java.util.Iterator; |
52 | 32 | import java.util.Collections;
|
| 33 | +import java.util.Iterator; |
53 | 34 | import java.util.List;
|
54 | 35 | import java.util.concurrent.Executors;
|
55 | 36 | import java.util.concurrent.ThreadFactory;
|
@@ -561,7 +542,28 @@ public void query(final Query query, final Consumer<QueryResult> onSuccess, fina
|
561 | 542 | call.enqueue(new Callback<QueryResult>() {
|
562 | 543 | @Override
|
563 | 544 | public void onResponse(final Call<QueryResult> call, final Response<QueryResult> response) {
|
564 |
| - onSuccess.accept(response.body()); |
| 545 | + if (response.isSuccessful()) { |
| 546 | + onSuccess.accept(response.body()); |
| 547 | + } else { |
| 548 | + Throwable t = null; |
| 549 | + String errorBody = null; |
| 550 | + |
| 551 | + try { |
| 552 | + if (response.errorBody() != null) { |
| 553 | + errorBody = response.errorBody().string(); |
| 554 | + } |
| 555 | + } catch (IOException e) { |
| 556 | + t = e; |
| 557 | + } |
| 558 | + |
| 559 | + if (t != null) { |
| 560 | + onFailure.accept(new InfluxDBException(response.message(), t)); |
| 561 | + } else if (errorBody != null) { |
| 562 | + onFailure.accept(new InfluxDBException(response.message() + " - " + errorBody)); |
| 563 | + } else { |
| 564 | + onFailure.accept(new InfluxDBException(response.message())); |
| 565 | + } |
| 566 | + } |
565 | 567 | }
|
566 | 568 |
|
567 | 569 | @Override
|
|
0 commit comments