Skip to content

Commit 0735d40

Browse files
author
Alex Gaetano Padula
committed
catch authentication error with new InvalidAuthenticationException
1 parent f23fec8 commit 0735d40

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

cursusdb.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
// CursusDB class
3232
class CursusDB {
33-
3433
// CursusDB client connection class
3534
static class Client {
3635
private String host; // Cluster host
@@ -43,6 +42,14 @@ static class Client {
4342
private Socket socket; // Socket
4443
private SSLSocket secureSocket; // Secured socket
4544

45+
46+
public class InvalidAuthenticationException
47+
extends RuntimeException {
48+
public InvalidAuthenticationException(String errorMessage) {
49+
super(errorMessage);
50+
}
51+
}
52+
4653
// Constructor for CursusDB Client
4754
Client(String hostIn, int portIn, String usernameIn, String passwordIn, boolean tlsIn) {
4855
host = hostIn;
@@ -87,6 +94,12 @@ void Connect() throws IOException {
8794

8895
String clusterResponse = reader.readLine();
8996

97+
if (clusterResponse.startsWith("0")) {
98+
99+
} else {
100+
throw new InvalidAuthenticationException("Could not authenticate to cluster");
101+
}
102+
90103

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

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package cursusdbjava;
1515
// Connect
1616
client.Connect();
1717
18-
} catch (IOException e) {
18+
} catch (IOException | CursusDB.Client.InvalidAuthenticationException e) {
1919
throw new RuntimeException(e);
2020
}
2121

test.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void main(String[] args) {
1212

1313
client.Connect();
1414

15-
} catch (IOException e) {
15+
} catch (IOException | CursusDB.Client.InvalidAuthenticationException e) {
1616
throw new RuntimeException(e);
1717
}
1818

0 commit comments

Comments
 (0)