Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 120ba0f

Browse files
committed
Added support for rate limiting by Etherscan: throw RateLimitException
1 parent 50d5799 commit 120ba0f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎src/main/java/io/api/etherscan/core/impl/BasicProvider.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package io.api.etherscan.core.impl;
22

33
import com.google.gson.Gson;
4+
import com.google.gson.JsonSyntaxException;
45
import io.api.etherscan.error.EtherScanException;
56
import io.api.etherscan.error.ParseException;
7+
import io.api.etherscan.error.RateLimitException;
68
import io.api.etherscan.executor.IHttpExecutor;
79
import io.api.etherscan.manager.IQueueManager;
810
import io.api.etherscan.util.BasicUtils;
911

12+
import java.util.Map;
13+
1014
/**
1115
* Base provider for API Implementations
1216
*
@@ -42,6 +46,19 @@ <T> T convert(final String json, final Class<T> tClass) {
4246
try {
4347
return gson.fromJson(json, tClass);
4448
} catch (Exception e) {
49+
if (e instanceof JsonSyntaxException) {
50+
Map<String, Object> map = gson.fromJson(json, Map.class);
51+
Object statusCode = map.get("status");
52+
if ((statusCode instanceof String) && (statusCode.equals("0"))) {
53+
Object message = map.get("message");
54+
if ((message instanceof String) && (message.equals("NOTOK"))) {
55+
Object result = map.get("result");
56+
if ((result instanceof String) && (result.equals("Max rate limit reached"))) {
57+
throw new RateLimitException ("Max rate limit reached");
58+
}
59+
}
60+
}
61+
}
4562
throw new ParseException(e.getMessage(), e.getCause(), json);
4663
}
4764
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.api.etherscan.error;
2+
3+
/**
4+
* ! NO DESCRIPTION !
5+
*
6+
* @author iSnow
7+
* @since 2020年10月06日
8+
*/
9+
public class RateLimitException extends ApiException {
10+
11+
public RateLimitException(String message) {
12+
super(message);
13+
}
14+
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /