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

[BUG] Client get request throws HttpException instead of LoginException #73

Open
Raft08 opened this issue Dec 26, 2023 · 8 comments
Open

Comments

@Raft08
Copy link

Raft08 commented Dec 26, 2023

Hello, I'm trying to make some check ups before running my code.

I do this code to get some information and to check if the panel is acccessible and I have a correct API token.

    private void checkoutAccount() {
        try {
            Account account = this.client.retrieveAccount()
                    .timeout(this.configuration.getTimeout(), TimeUnit.MILLISECONDS)
                    .execute();

            if (!account.isRootAdmin())
                Bootstrap.crash("Pterodactyl account is missing permissions. Administration permissions are required by AtlasNetwork.");

            LOGGER.info("Connected as {}!", account.getUserName());
        } catch (LoginException | HttpException e) {
            Bootstrap.crash("Could not open connection with '" +
                    this.configuration.getUrl() + ": Invalid Authentication Token!");
        }
    }

But when I'm unauthenticated. it throws HttpException instead of LoginException is this expected behaviour?

The javadoc says "Throws: LoginException – If the API key is incorrect"

@mattmalec
Copy link
Owner

Is the API key valid, but missing certain permissions?

@Raft08
Copy link
Author

Raft08 commented Dec 26, 2023

Nope I gave a wrong api key just for testing

I gave 'some-token' as api key just to test that code

@mattmalec
Copy link
Owner

How do you know it's throwing a HttpException? If we get a 403 from the panel, we throw a LoginException (see here: https://github.com/mattmalec/Pterodactyl4J/blob/develop/src/main/java/com/mattmalec/pterodactyl4j/requests/Request.java#L73-L76)

@Raft08
Copy link
Author

Raft08 commented Dec 27, 2023

With the code up there if I don't catch the HttpException it simply makes my application crash, I'm forced to handle the HttpException as a login issue if I want the application to gracefully crash.

image

It's not an OkHttp HttpException but your library's HttpException (com.mattmalec.pterodactyl4j.exceptions.HttpException)

@Raft08
Copy link
Author

Raft08 commented Dec 27, 2023

It seems that the panel if the API key is wrong doesn't return 403 code but an 401 code

@mattmalec
Copy link
Owner

Definitely looks like a bug then - want to throw up a PR? Sounds like we can just have a 401 case and fallthrough to the 403 logic

@Raft08
Copy link
Author

Raft08 commented Dec 27, 2023

I could do that but won't it be better to simply report this issue to pterodactyl directly? At least to know if it is expected behaviour from the panel to return 401 instead of 403

@Raft08
Copy link
Author

Raft08 commented Dec 27, 2023

I'm going to make a PR for this bug and another bug that I found.

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