From c084d29518c74d5cb782871fa0a6d73bc14a53c2 Mon Sep 17 00:00:00 2001 From: luluxe Date: Tue, 14 Feb 2023 13:35:43 +0100 Subject: [PATCH] Error and debug to sent session --- .../communityanalytics/spigot/api/ApiResponse.java | 4 ++++ .../spigot/managers/PlatformManager.java | 1 + .../spigot/managers/SessionManager.java | 13 ++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/communityanalytics/spigot/api/ApiResponse.java b/src/main/java/net/communityanalytics/spigot/api/ApiResponse.java index 72e3483..e304e73 100644 --- a/src/main/java/net/communityanalytics/spigot/api/ApiResponse.java +++ b/src/main/java/net/communityanalytics/spigot/api/ApiResponse.java @@ -11,6 +11,10 @@ public ApiResponse(java.net.http.HttpResponse response) { this.response = response; } + public boolean has(String arg) { + return JsonParser.parseString(response.body()).getAsJsonObject().has(arg); + } + public String getStringArg(String arg) { return JsonParser.parseString(response.body()).getAsJsonObject().get(arg).getAsString(); } diff --git a/src/main/java/net/communityanalytics/spigot/managers/PlatformManager.java b/src/main/java/net/communityanalytics/spigot/managers/PlatformManager.java index d887069..6ad9980 100644 --- a/src/main/java/net/communityanalytics/spigot/managers/PlatformManager.java +++ b/src/main/java/net/communityanalytics/spigot/managers/PlatformManager.java @@ -15,6 +15,7 @@ public void getPlatformInfo() { SpigotPlugin.logger().printError("Can't auth to API:"); SpigotPlugin.logger().printError("Check your token in config.yml"); error(); + return; } success = true; diff --git a/src/main/java/net/communityanalytics/spigot/managers/SessionManager.java b/src/main/java/net/communityanalytics/spigot/managers/SessionManager.java index 71d9d8c..241db41 100644 --- a/src/main/java/net/communityanalytics/spigot/managers/SessionManager.java +++ b/src/main/java/net/communityanalytics/spigot/managers/SessionManager.java @@ -6,6 +6,7 @@ import net.communityanalytics.spigot.SpigotAPI; import net.communityanalytics.spigot.SpigotPlugin; import net.communityanalytics.spigot.api.APIRequest; +import net.communityanalytics.spigot.api.ApiResponse; import net.communityanalytics.spigot.data.Session; import java.util.*; @@ -81,7 +82,17 @@ public void sendAPI() { APIRequest request = SpigotAPI.sessionStore(data); try { - request.sendRequest(); + ApiResponse response = request.sendRequest(); + if (response.getStatus() == 402) { + SpigotPlugin.logger().printError("Your subscription no longer allows you to receive new information. Please upgrade your subscription."); + return; + } + if (response.getStatus() != 200) { + SpigotPlugin.logger().printError("Can't auth to API: Check your token in config.yml"); + return; + } + + SpigotPlugin.logger().printDebug("Sessions sent to API with success."); } catch (Exception e) { e.printStackTrace(); }