Skip to content

Commit

Permalink
Error and debug to sent session
Browse files Browse the repository at this point in the history
  • Loading branch information
luluxe committed Feb 14, 2023
1 parent 605e058 commit c084d29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public ApiResponse(java.net.http.HttpResponse<String> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit c084d29

Please sign in to comment.