I am handling the exception on addDisconnectedListener and on connection fail just logging internal log but what is exact reason for failure. I am getting this cast exception but i am not doing any casting just logging the exception
com.hivemq.client.mqtt.exceptions.ConnectionFailedException: java.lang.ClassCastException: android.os.NetworkOnMainThreadException cannot be cast to java.net.UnknownHostException
private fun handleMqttDisconnect(context: MqttClientDisconnectedContext) {
when (context.cause) {
is Mqtt5DisconnectException -> {
handleDisconnectException(context)
}
// if the ConnAck message contained an error code (the ConnAck message is contained in the exception)
is Mqtt5ConnAckException -> {
handleConnectionAckException(context)
}
// if the connection is closed after the Connect message has been sent but before a ConnAck message has been received
is ConnectionClosedException -> {
if (context.source == MqttDisconnectSource.SERVER) {
logMqtt("WSConnMgr ::!! ConnectionClosedException !!", "e")
sendSNSAlert(context)
// setting it to false, otherwise its going in infinite loop of exception callback.
context.reconnector.reconnect(false)
} else {
sendSNSAlert(context)
}
}
// if an error occurs before the Connect message could be sent
// if the internet is off coming to this exception
is ConnectionFailedException -> {
sendSNSAlert(context)
logMqtt("WSConnMgr ::!! ConnectionFailedException !!", "e")
}
}
if (context.cause.toString().contains("NOT_AUTHORIZED")) {
forceLogoutUser(context)
}
}