forked from j62/ctbrec
1
0
Fork 0

Improve exception handling for update check

This commit is contained in:
0xboobface 2019-12-31 14:28:54 +01:00
parent 1ec2cf5286
commit 549133e6a7
1 changed files with 8 additions and 3 deletions

View File

@ -32,6 +32,7 @@ import ctbrec.event.EventBusHolder;
import ctbrec.event.EventHandler;
import ctbrec.event.EventHandlerConfiguration;
import ctbrec.io.HttpClient;
import ctbrec.io.HttpException;
import ctbrec.recorder.NextGenLocalRecorder;
import ctbrec.recorder.OnlineMonitor;
import ctbrec.recorder.Recorder;
@ -363,11 +364,13 @@ public class CamrecApplication extends Application {
String url = "https://pastebin.com/raw/mUxtKzyB";
Request request = new Request.Builder().url(url).build();
try (Response response = httpClient.execute(request)) {
String body = response.body().string();
LOG.trace("Version check respone: {}", body);
if (response.isSuccessful()) {
Moshi moshi = new Moshi.Builder().build();
Type type = Types.newParameterizedType(List.class, Release.class);
JsonAdapter<List<Release>> adapter = moshi.adapter(type);
List<Release> releases = adapter.fromJson(response.body().source());
List<Release> releases = adapter.fromJson(body);
Release latest = releases.get(0);
Version latestVersion = latest.getVersion();
Version ctbrecVersion = getVersion();
@ -377,9 +380,11 @@ public class CamrecApplication extends Application {
} else {
LOG.debug("ctbrec is up-to-date {}", ctbrecVersion);
}
} else {
throw new HttpException(response.code(), response.message());
}
} catch (IOException e) {
LOG.warn("Update check failed {}", e.getMessage());
} catch (Exception e) {
LOG.warn("Update check failed: {}", e.getMessage());
}
});
updateCheck.setName("Update Check");