Skip to content

Commit d7ab7ec

Browse files
iSnowGoodforGod
authored andcommitted
Added better handling of communication errors
(cherry picked from commit 2893283)
1 parent 1e03995 commit d7ab7ec

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/java/io/api/etherscan/error/ConnectionException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
*/
99
public class ConnectionException extends ApiException {
1010

11+
public ConnectionException(String message) {
12+
super(message);
13+
}
14+
1115
public ConnectionException(String message, Throwable cause) {
1216
super(message, cause);
1317
}

src/main/java/io/api/etherscan/executor/impl/HttpExecutor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import java.util.zip.GZIPInputStream;
1919
import java.util.zip.InflaterInputStream;
2020

21-
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
22-
import static java.net.HttpURLConnection.HTTP_MOVED_TEMP;
21+
import static java.net.HttpURLConnection.*;
2322

2423
/**
2524
* Http client implementation
@@ -88,6 +87,10 @@ public String get(final String urlAsString) {
8887
final int status = connection.getResponseCode();
8988
if (status == HTTP_MOVED_TEMP || status == HTTP_MOVED_PERM) {
9089
return get(connection.getHeaderField("Location"));
90+
} else if ((status >= HTTP_BAD_REQUEST) && (status < HTTP_INTERNAL_ERROR)) {
91+
throw new ConnectionException("Protocol error: "+connection.getResponseMessage());
92+
} else if (status >= HTTP_INTERNAL_ERROR) {
93+
throw new ConnectionException("Server error: "+connection.getResponseMessage());
9194
}
9295

9396
final String data = readData(connection);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy