java-sdk icon indicating copy to clipboard operation
java-sdk copied to clipboard

Warning when using incorrect token.

Open spide-r opened this issue 6 years ago • 5 comments

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.

spide-r avatar Oct 14 '18 03:10 spide-r

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.

nikammerlaan avatar Oct 21 '18 06:10 nikammerlaan

There would be a 401 unauthorized response if an invalid token is used. No?

spide-r avatar Oct 22 '18 03:10 spide-r

Well yeah, but what would it call to receive that response?

nikammerlaan avatar Oct 23 '18 04:10 nikammerlaan

maybe throw an exception when the user attempts to update stats?

spide-r avatar Oct 26 '18 18:10 spide-r

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
}

nikammerlaan avatar Oct 26 '18 19:10 nikammerlaan