java-sdk
java-sdk copied to clipboard
Warning when using incorrect token.
When you attempt to set the stats of your bot with an invalid token, there is no indication that your token is invalid. It would be helpful to know whether or not the token is working or not.
I'm unsure how one would go about implementing this. Afaik, there isn't an endpoint you can call to verify the validity of the token. I'll ask the API dev at DBL.
There would be a 401 unauthorized response if an invalid token is used. No?
Well yeah, but what would it call to receive that response?
maybe throw an exception when the user attempts to update stats?
Oh, I'm so sorry - I totally misread your initial issue. I believed you meant that you wanted it to validate the token upon building the API client.
Since the entire API client is async, you need to handle the exception async or transform the CompletionStage into a CompletableFuture and use the blocking get()
method. Here's an example of both:
int serverCount = 1234;
api.setStats(serverCount).whenComplete((v, e) -> {
// if e is not null, then there was an exception
});
try {
api.setStats(serverCount).toCompletableFuture().get();
} catch(Exception e) {
// exception
}