Skip to content

Commit

Permalink
Added automatic retries when receiving null responses from GameBanana
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Feb 20, 2021
1 parent ad87194 commit d382216
Show file tree
Hide file tree
Showing 8 changed files with 1,751 additions and 1,352 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Get Maven, then run the following command at the project root:
mvn clean package
```

This will build the project to `target/update-checker-0.0.13.jar`.
This will build the project to `target/update-checker-0.0.14.jar`.

## Running the project

Expand All @@ -61,7 +61,7 @@ First, follow these steps to set it up:
Then, to run the project, browse to where the JAR is in a terminal / command prompt, then run

```
java -jar update-checker-0.0.13.jar [port] [minutes]
java -jar update-checker-0.0.14.jar [port] [minutes]
```
[port] is the HTTP port for the server. If you don't provide any, there won't be any server hosted (useful if you already have something else hosting the files).
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.max480.everest.updatechecker</groupId>
<artifactId>update-checker</artifactId>
<version>0.0.13</version>
<version>0.0.14</version>

<properties>
<jdk.version>1.8</jdk.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ private boolean loadPage(int page) throws IOException {

List<List<Object>> mods = runWithRetry(() -> {
try (InputStream is = openStreamWithTimeout(new URL("https://api.gamebanana.com/Core/List/New?page=" + page + "&gameid=6460&format=yaml"))) {
return new Yaml().load(is);
return Optional.ofNullable(new Yaml().<List<List<Object>>>load(is))
.orElseThrow(() -> new IOException("Ended up with a null value when loading a mod page"));
}
});

Expand Down Expand Up @@ -233,7 +234,8 @@ private void loadPageModInfo(String modInfoUrl, List<QueriedModInfo> queriedModI
log.trace("Mod info URL: {}", modInfoUrl);
List<List<Object>> mods = runWithRetry(() -> {
try (InputStream is = openStreamWithTimeout(new URL(modInfoUrl))) {
return new Yaml().load(is);
return Optional.ofNullable(new Yaml().<List<List<Object>>>load(is))
.orElseThrow(() -> new IOException("Ended up with a null value when loading mod info"));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ private void fetchAuthorNames() throws IOException {
// run the request, parse the result, and add this result to the list.
authorNames = DatabaseUpdater.runWithRetry(() -> {
try (InputStream is = DatabaseUpdater.openStreamWithTimeout(new URL(url))) {
return new Yaml().load(is);
return Optional.ofNullable(new Yaml().<List<List<Object>>>load(is))
.orElseThrow(() -> new IOException("Ended up with a null value when loading a mod page"));
}
});
}
Expand Down
Loading

0 comments on commit d382216

Please sign in to comment.