Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace RuntimeException with InfluxDBException #323

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/org/influxdb/InfluxDBException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.influxdb;

/**
* A wrapper for various exceptions caused while interacting with InfluxDB.
*
* @author Simon Legner
*/
public class InfluxDBException extends RuntimeException {

public InfluxDBException(final String message) {
super(message);
}

public InfluxDBException(final String message, final Throwable cause) {
super(message, cause);
}

public InfluxDBException(final Throwable cause) {
super(cause);
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/influxdb/InfluxDBIOException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.influxdb;

import java.io.IOException;

/**
* A wrapper for {@link IOException} caused while interacting with InfluxDB.
*
* @author Simon Legner
*/
public class InfluxDBIOException extends InfluxDBException {

public InfluxDBIOException(final IOException cause) {
super(cause);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/influxdb/dto/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static String encode(final String command) {
try {
return URLEncoder.encode(command, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
throw new IllegalStateException("Every JRE must support UTF-8", e);
}
}
}
22 changes: 12 additions & 10 deletions src/main/java/org/influxdb/impl/InfluxDBImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.squareup.moshi.Moshi;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBException;
import org.influxdb.InfluxDBIOException;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.influxdb.dto.Pong;
Expand Down Expand Up @@ -99,7 +101,7 @@ private InetAddress parseHostAddress(final String url) {
try {
return InetAddress.getByName(HttpUrl.parse(url).host());
} catch (UnknownHostException e) {
throw new RuntimeException(e);
throw new InfluxDBIOException(e);
}
}

Expand Down Expand Up @@ -221,7 +223,7 @@ public Pong ping() {
pong.setResponseTime(watch.elapsed(TimeUnit.MILLISECONDS));
return pong;
} catch (IOException e) {
throw new RuntimeException(e);
throw new InfluxDBIOException(e);
}
}

Expand Down Expand Up @@ -304,7 +306,7 @@ public void write(final int udpPort, final String records) {
try {
datagramSocket.send(new DatagramPacket(bytes, bytes.length, hostAddress, udpPort));
} catch (IOException e) {
throw new RuntimeException(e);
throw new InfluxDBIOException(e);
}
}

Expand All @@ -315,7 +317,7 @@ private void initialDatagramSocket() {
try {
datagramSocket = new DatagramSocket();
} catch (SocketException e) {
throw new RuntimeException(e);
throw new InfluxDBIOException(e);
}
}
}
Expand Down Expand Up @@ -354,7 +356,7 @@ public QueryResult query(final Query query) {
public void query(final Query query, final int chunkSize, final Consumer<QueryResult> consumer) {

if (version().startsWith("0.") || version().startsWith("1.0")) {
throw new RuntimeException("chunking not supported");
throw new UnsupportedOperationException("chunking not supported");
}

Call<ResponseBody> call = this.influxDBService.query(this.username, this.password,
Expand All @@ -374,20 +376,20 @@ public void onResponse(final Call<ResponseBody> call, final Response<ResponseBod
}
}
try (ResponseBody errorBody = response.errorBody()) {
throw new RuntimeException(errorBody.string());
throw new InfluxDBException(errorBody.string());
}
} catch (EOFException e) {
QueryResult queryResult = new QueryResult();
queryResult.setError("DONE");
consumer.accept(queryResult);
} catch (IOException e) {
throw new RuntimeException(e);
throw new InfluxDBIOException(e);
}
}

@Override
public void onFailure(final Call<ResponseBody> call, final Throwable t) {
throw new RuntimeException(t);
throw new InfluxDBException(t);
}
});
}
Expand Down Expand Up @@ -463,10 +465,10 @@ private <T> T execute(final Call<T> call) {
return response.body();
}
try (ResponseBody errorBody = response.errorBody()) {
throw new RuntimeException(errorBody.string());
throw new InfluxDBException(errorBody.string());
}
} catch (IOException e) {
throw new RuntimeException(e);
throw new InfluxDBIOException(e);
}
}

Expand Down