Skip to content

Commit a4e4b09

Browse files
iSnowGoodforGod
authored andcommitted
Added support for rate limiting by Etherscan: throw RateLimitException
(cherry picked from commit 120ba0f)
1 parent 5729da7 commit a4e4b09

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)
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