Skip to content

Commit

Permalink
catch authentication error with new InvalidAuthenticationException
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gaetano Padula committed Dec 24, 2023
1 parent f23fec8 commit 0735d40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion cursusdb.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

// CursusDB class
class CursusDB {

// CursusDB client connection class
static class Client {
private String host; // Cluster host
Expand All @@ -43,6 +42,14 @@ static class Client {
private Socket socket; // Socket
private SSLSocket secureSocket; // Secured socket


public class InvalidAuthenticationException
extends RuntimeException {
public InvalidAuthenticationException(String errorMessage) {
super(errorMessage);
}
}

// Constructor for CursusDB Client
Client(String hostIn, int portIn, String usernameIn, String passwordIn, boolean tlsIn) {
host = hostIn;
Expand Down Expand Up @@ -87,6 +94,12 @@ void Connect() throws IOException {

String clusterResponse = reader.readLine();

if (clusterResponse.startsWith("0")) {

} else {
throw new InvalidAuthenticationException("Could not authenticate to cluster");
}


System.out.println("Connected to cluster.");

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package cursusdbjava;
// Connect
client.Connect();
} catch (IOException e) {
} catch (IOException | CursusDB.Client.InvalidAuthenticationException e) {
throw new RuntimeException(e);
}
Expand Down
2 changes: 1 addition & 1 deletion test.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void main(String[] args) {

client.Connect();

} catch (IOException e) {
} catch (IOException | CursusDB.Client.InvalidAuthenticationException e) {
throw new RuntimeException(e);
}

Expand Down

0 comments on commit 0735d40

Please sign in to comment.