-
Notifications
You must be signed in to change notification settings - Fork 41
Better connection exception reporting and small changes #6
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d27d01a
Method to get an event time stamp as milliseconds since the Unix epoc…
iSnow cf2d386
Added Jitpack link for snapshots
iSnow 8de0601
Method to get an event time stamp as milliseconds since the Unix epoc…
iSnow 903a188
Merge remote-tracking branch 'origin/master'
iSnow 235be0d
Method to get all events without a topic filter
iSnow ec0cf80
Higher-level API to read well-known ETH events as polymorphic classes
iSnow 2893283
Added better handling of communication errors
iSnow 6494764
Removed events stuff again, moved to different library
iSnow 67b695d
Removed events stuff again, moved to different library
iSnow 278396a
Update README.md
iSnow ccda631
Update README.md
iSnow dffeda7
Update README.md
iSnow 577c38d
Update README.md
iSnow 5c79d66
Removed events stuff again, moved to different library
iSnow 2e61c0f
Merge remote-tracking branch 'origin/master'
iSnow 50d5799
Removed events stuff again, moved to different library
iSnow 120ba0f
Added support for rate limiting by Etherscan: throw RateLimitException
iSnow f7bb00c
added getter for the JSON string to ParseException
iSnow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
.idea/ | ||
# Compiled class files | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
**/.log | ||
|
||
# IntelliJ | ||
*.iml | ||
/.idea | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# other | ||
/bin/ | ||
/.classpath | ||
/.project | ||
/target/ | ||
/out/ | ||
/.DS_Store | ||
/.settings/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package io.api.etherscan.core.impl; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonSyntaxException; | ||
import io.api.etherscan.error.EtherScanException; | ||
import io.api.etherscan.error.ParseException; | ||
import io.api.etherscan.error.RateLimitException; | ||
import io.api.etherscan.executor.IHttpExecutor; | ||
import io.api.etherscan.manager.IQueueManager; | ||
import io.api.etherscan.util.BasicUtils; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Base provider for API Implementations | ||
* | ||
|
@@ -42,7 +46,20 @@ <T> T convert(final String json, final Class<T> tClass) { | |
try { | ||
return gson.fromJson(json, tClass); | ||
} catch (Exception e) { | ||
throw new ParseException(e.getMessage(), e.getCause()); | ||
if (e instanceof JsonSyntaxException) { | ||
Map<String, Object> map = gson.fromJson(json, Map.class); | ||
Object statusCode = map.get("status"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the point to check for status & message if you only consider result field in the end? |
||
if ((statusCode instanceof String) && (statusCode.equals("0"))) { | ||
Object message = map.get("message"); | ||
if ((message instanceof String) && (message.equals("NOTOK"))) { | ||
Object result = map.get("result"); | ||
if ((result instanceof String) && (result.equals("Max rate limit reached"))) { | ||
throw new RateLimitException ("Max rate limit reached"); | ||
} | ||
} | ||
} | ||
} | ||
throw new ParseException(e.getMessage(), e.getCause(), json); | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,14 @@ | |
* @since 29.10.2018 | ||
*/ | ||
public class ParseException extends ApiException { | ||
String json; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private final it should be |
||
|
||
public ParseException(String message, Throwable cause) { | ||
public ParseException(String message, Throwable cause, String json) { | ||
super(message, cause); | ||
this.json = json; | ||
} | ||
|
||
public String getJson() { | ||
return json; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/io/api/etherscan/error/RateLimitException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.api.etherscan.error; | ||
|
||
/** | ||
* ! NO DESCRIPTION ! | ||
* | ||
* @author iSnow | ||
* @since 2020-10-06 | ||
*/ | ||
public class RateLimitException extends ApiException { | ||
|
||
public RateLimitException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this should be linked to https://jitpack.io/#goodforgod/java-etherscan-api as other links too