|
1 | 1 | package io.api.etherscan.core.impl; |
2 | 2 |
|
3 | 3 | import com.google.gson.Gson; |
| 4 | +import com.google.gson.JsonSyntaxException; |
4 | 5 | import io.api.etherscan.error.EtherScanException; |
5 | 6 | import io.api.etherscan.error.ParseException; |
| 7 | +import io.api.etherscan.error.RateLimitException; |
6 | 8 | import io.api.etherscan.executor.IHttpExecutor; |
7 | 9 | import io.api.etherscan.manager.IQueueManager; |
8 | 10 | import io.api.etherscan.util.BasicUtils; |
9 | 11 |
|
| 12 | +import java.util.Map; |
| 13 | + |
10 | 14 | /** |
11 | 15 | * Base provider for API Implementations |
12 | 16 | * |
@@ -42,6 +46,19 @@ <T> T convert(final String json, final Class<T> tClass) { |
42 | 46 | try { |
43 | 47 | return gson.fromJson(json, tClass); |
44 | 48 | } 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 | + } |
45 | 62 | throw new ParseException(e.getMessage(), e.getCause(), json); |
46 | 63 | } |
47 | 64 | } |
|
0 commit comments