Handle subscribe exceptions
This commit is contained in:
@@ -65,7 +65,7 @@ public class MqttService {
|
||||
connect(subscriber, options);
|
||||
|
||||
subscriber.subscribe(topic, 1);
|
||||
} catch (MqttException e) {
|
||||
} catch (Exception e) {
|
||||
Logger.displayError("An error occurred while subscribing : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -101,12 +101,16 @@ public class MqttService {
|
||||
}
|
||||
|
||||
private void connect(MqttClient client, MqttConnectOptions options) throws MqttException {
|
||||
if (client.isConnected()) return;
|
||||
if (options == null) {
|
||||
client.connect();
|
||||
} else {
|
||||
client.connect(options);
|
||||
try {
|
||||
if (client.isConnected()) return;
|
||||
if (options == null) {
|
||||
client.connect();
|
||||
} else {
|
||||
client.connect(options);
|
||||
}
|
||||
Logger.displayInfo("Connected to " + client.getCurrentServerURI());
|
||||
} catch (Exception e){
|
||||
Logger.displayError("Unable to connect to broker : " + e.getMessage());
|
||||
}
|
||||
Logger.displayInfo("Connected to " + client.getCurrentServerURI());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user