Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning when using incorrect token. #5

Open
spide-r opened this issue Oct 14, 2018 · 5 comments
Open

Warning when using incorrect token. #5

spide-r opened this issue Oct 14, 2018 · 5 comments

Comments

@spide-r
Copy link

spide-r commented Oct 14, 2018

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.

@nikammerlaan
Copy link
Contributor

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.

@spide-r
Copy link
Author

spide-r commented Oct 22, 2018

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

@nikammerlaan
Copy link
Contributor

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

@spide-r
Copy link
Author

spide-r commented Oct 26, 2018

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

@nikammerlaan
Copy link
Contributor

nikammerlaan commented Oct 26, 2018

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants