From 549133e6a78e391a486f2e5522ce62dab0cde682 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Tue, 31 Dec 2019 14:28:54 +0100 Subject: [PATCH] Improve exception handling for update check --- client/src/main/java/ctbrec/ui/CamrecApplication.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index c640aaa2..1c5f892c 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -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> adapter = moshi.adapter(type); - List releases = adapter.fromJson(response.body().source()); + List 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");