Skip to content

Commit d38b4a8

Browse files
committed
Make RatelimitedException a RuntimeException
1 parent eb7d561 commit d38b4a8

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins{
77
id 'com.github.johnrengelman.shadow' version '5.2.0'
88
}
99

10-
def ver = new Version(major: 5, minor: 1, revision: 6)
10+
def ver = new Version(major: 5, minor: 1, revision: 7)
1111

1212
group = "org.botblock"
1313
version = "$ver"
@@ -27,7 +27,7 @@ dependencies{
2727
api group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.3.1'
2828
api group: 'org.json', name: 'json', version: '20190722'
2929
api group: 'org.jetbrains', name: 'annotations', version: '18.0.0'
30-
api(group: 'net.dv8tion', name: 'JDA', version: '4.1.0_100'){
30+
api(group: 'net.dv8tion', name: 'JDA', version: '4.1.1_101'){
3131
exclude(module: 'opus-java')
3232
}
3333
api group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.8.0'

src/main/java/org/botblock/javabotblockapi/exceptions/RatelimitedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Indicates that the Java-Wrapper (Bot) was rate-limited by BotBlock.org (Received error code 429)
2424
* <br>The returned error message contains the route, Bot ID, IP and delay in seconds for when rate limit is removed.
2525
*/
26-
public class RatelimitedException extends Throwable{
26+
public class RatelimitedException extends RuntimeException{
2727
private int delay;
2828
private String bot_id;
2929
private String ip;

src/main/java/org/botblock/javabotblockapi/requests/RequestHandler.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ JSONObject performGetBot(@NotNull String id, boolean disableCache){
6161

6262
try{
6363
return performGET(url);
64-
}catch(IOException | RatelimitedException ex){
64+
}catch(IOException ex){
6565
ex.printStackTrace();
6666
return null;
6767
}
@@ -85,7 +85,7 @@ JSONObject performGetList(@NotNull String id, @Nullable String site, boolean dis
8585
return listCache.get(id, k -> {
8686
try{
8787
return performGET(finalUrl);
88-
}catch(IOException | RatelimitedException ex){
88+
}catch(IOException ex){
8989
ex.printStackTrace();
9090
return null;
9191
}
@@ -94,14 +94,14 @@ JSONObject performGetList(@NotNull String id, @Nullable String site, boolean dis
9494

9595
try{
9696
return performGET(url);
97-
}catch(IOException | RatelimitedException ex){
97+
}catch(IOException ex){
9898
ex.printStackTrace();
9999
return null;
100100
}
101101

102102
}
103103

104-
private JSONObject performGET(@NotNull String url) throws IOException, RatelimitedException{
104+
private JSONObject performGET(@NotNull String url) throws IOException{
105105
Request request = new Request.Builder()
106106
.url(url)
107107
.build();
@@ -111,12 +111,13 @@ private JSONObject performGET(@NotNull String url) throws IOException, Ratelimit
111111
if(body == null)
112112
throw new NullPointerException("Received empty response body.");
113113

114-
if(body.string().isEmpty())
114+
String bodyString = body.string();
115+
if(bodyString.isEmpty())
115116
throw new NullPointerException("Received empty response body.");
116117

117118
if(!response.isSuccessful()){
118119
if(response.code() == 429)
119-
throw new RatelimitedException(body.string());
120+
throw new RatelimitedException(bodyString);
120121

121122
throw new IOException(String.format(
122123
"Could not retrieve information. The server responded with error code %d (%s).",
@@ -125,11 +126,11 @@ private JSONObject performGET(@NotNull String url) throws IOException, Ratelimit
125126
));
126127
}
127128

128-
return new JSONObject(body.string());
129+
return new JSONObject(bodyString);
129130
}
130131
}
131132

132-
void performPOST(@NotNull JSONObject json, int sites) throws IOException, RatelimitedException{
133+
void performPOST(@NotNull JSONObject json, int sites) throws IOException{
133134
if(sites < 1)
134135
throw new IllegalStateException("POST action requires at least one site!");
135136

@@ -154,12 +155,13 @@ void performPOST(@NotNull JSONObject json, int sites) throws IOException, Rateli
154155
if(responseBody == null)
155156
throw new NullPointerException("Received empty response body.");
156157

157-
if(responseBody.string().isEmpty())
158+
String bodyString = responseBody.string();
159+
if(bodyString.isEmpty())
158160
throw new NullPointerException("Received empty response body.");
159161

160162
if(!response.isSuccessful()){
161163
if(response.code() == 429)
162-
throw new RatelimitedException(responseBody.string());
164+
throw new RatelimitedException(bodyString);
163165

164166
throw new IOException(String.format(
165167
"Could not post Guild count. The server responded with error code %d (%s)",

0 commit comments

Comments
 (0)