Skip to content

Commit d18f6de

Browse files
committed
Play local audio message where there is an authentication error
1 parent 9411865 commit d18f6de

File tree

7 files changed

+1407
-1200
lines changed

7 files changed

+1407
-1200
lines changed

speech/error-client-create.flac

82.4 KB
Binary file not shown.

src/main/java/Driver.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import wa.audio.LocalAudio;
2525
import wa.client.Client;
26+
import wa.exceptions.AuthenticationError;
2627

2728

2829
/**
@@ -34,8 +35,9 @@
3435
* This does not exit unless:
3536
* <bl>
3637
* <li> It cannot open/read the configure.properties file (Exit=1)
37-
* <li> It cannot create and initialize the Client (Exit=1)
38-
* <li> There is a 'catastrophic' error from the client (Exit=3)
38+
* <li> It cannot create and initialize the Client (Exit=2)
39+
* <li> The client could not authenticate with the server (Exit=3)
40+
* <li> There is a 'catastrophic' error from the client (Exit=4)
3941
* <li> The process is externally terminated
4042
* </bl>
4143
*
@@ -60,14 +62,7 @@ public static void main(String args[]) {
6062
Properties properties = readProps();
6163
if (null == properties) {
6264
LOG.error("The configure.properties was not found, could not be read, or is not in valid properties file format. The configure.properties file should be in the 'config' folder.");
63-
try {
64-
LocalAudio.playFlacFile(LocalAudio.ERROR_NO_CONFIG_FILE);
65-
}
66-
catch (Throwable t) {
67-
// At this point - just exit
68-
// (log it, just in case it helps improve the responses)
69-
LOG.error("-- could not PLAY response audio due to: " + t, t);
70-
}
65+
playLocalFlacAudio(LocalAudio.ERROR_NO_CONFIG_FILE);
7166
System.exit(1);
7267
}
7368

@@ -78,6 +73,7 @@ public static void main(String args[]) {
7873
catch (Throwable t) {
7974
// Any error from creating the client causes this to exit(2)
8075
LOG.error("Problem trying to create and initialize the client: " + t, t);
76+
playLocalFlacAudio(LocalAudio.ERROR_CLIENT_CREATE);
8177
System.exit(2);
8278
}
8379

@@ -95,13 +91,38 @@ public static void main(String args[]) {
9591
}
9692
}
9793
LOG.info("Client is done!");
94+
// Check for an error.
95+
RuntimeException error = client.getError();
96+
if (null != error && error instanceof AuthenticationError) {
97+
playLocalFlacAudio(LocalAudio.ERROR_AUTH);
98+
System.exit(3);
99+
}
98100
} catch (RuntimeException re) {
99101
LOG.error("Exiting due to thrown RuntimeException", re);
102+
System.exit(4);
100103
} catch (Error err) {
101104
LOG.error("Exiting due to thrown Error", err);
105+
System.exit(4);
102106
}
103107
}
104108

109+
/**
110+
* Play a local audio file safely (catch any exception that occurs
111+
* while playing and log it).
112+
*
113+
* @param flacFileName - Name of the FLAC audio file to play
114+
*/
115+
private static void playLocalFlacAudio(String flacFileName) {
116+
try {
117+
LocalAudio.playFlacFile(flacFileName);
118+
}
119+
catch (Throwable t) {
120+
// At this point - just exit
121+
// (log it, just in case it helps improve the responses)
122+
LOG.error("-- could not PLAY response audio due to: " + t, t);
123+
}
124+
}
125+
105126
/**
106127
* Reads the configure.properties file
107128
*

src/main/java/wa/audio/LocalAudio.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ public class LocalAudio {
3838
private static final Logger LOG = LogManager.getLogger(LocalAudio.class);
3939

4040
public static final String ERROR_AUTH = "error-auth";
41+
public static final String ERROR_CLIENT_CREATE = "error-client-create";
4142
public static final String ERROR_INVALID_CONFIG = "error-config";
42-
public static final String ERROR_NO_CONFIG_FILE = "error-no-config-file";
4343
public static final String ERROR_NETWORK = "error-network";
44+
public static final String ERROR_NO_CONFIG_FILE = "error-no-config-file";
45+
4446
public static final String ABORTING = "aborting";
4547

4648
public static final String ANNOUNCE_IP = "announce-ip";

0 commit comments

Comments
 (0)