Improve MQTT connection error reporting
This commit is contained in:
@@ -76,7 +76,7 @@ class Mqtt(object):
|
|||||||
try:
|
try:
|
||||||
j = _util.parse_json(message.payload)
|
j = _util.parse_json(message.payload)
|
||||||
except _exception.FBchatFacebookError:
|
except _exception.FBchatFacebookError:
|
||||||
log.exception("Failed parsing MQTT data as JSON: %r", message.payload)
|
log.exception("Failed parsing MQTT data on %s as JSON", message.topic)
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.topic == "/t_ms":
|
if message.topic == "/t_ms":
|
||||||
@@ -241,13 +241,15 @@ class Mqtt(object):
|
|||||||
|
|
||||||
if rc != paho.mqtt.client.MQTT_ERR_SUCCESS:
|
if rc != paho.mqtt.client.MQTT_ERR_SUCCESS:
|
||||||
err = paho.mqtt.client.error_string(rc)
|
err = paho.mqtt.client.error_string(rc)
|
||||||
log.warning("MQTT Error: %s", err)
|
|
||||||
if on_error:
|
# If known/expected error
|
||||||
# Temporary to support on_error param
|
if rc in [paho.mqtt.client.MQTT_ERR_CONN_LOST]:
|
||||||
try:
|
log.warning(err)
|
||||||
raise _exception.FBchatException("MQTT Error: {}".format(err))
|
else:
|
||||||
except _exception.FBchatException as e:
|
log.warning("MQTT Error: %s", err)
|
||||||
on_error(exception=e)
|
# For backwards compatibility
|
||||||
|
if on_error:
|
||||||
|
on_error(exception=FBchatException("MQTT Error {}".format(err)))
|
||||||
|
|
||||||
# Wait before reconnecting
|
# Wait before reconnecting
|
||||||
self._mqtt._reconnect_wait()
|
self._mqtt._reconnect_wait()
|
||||||
@@ -262,7 +264,7 @@ class Mqtt(object):
|
|||||||
OSError,
|
OSError,
|
||||||
paho.mqtt.client.WebsocketConnectionError,
|
paho.mqtt.client.WebsocketConnectionError,
|
||||||
):
|
):
|
||||||
log.debug("MQTT connection failed")
|
log.debug("MQTT reconnection failed")
|
||||||
|
|
||||||
return True # Keep listening
|
return True # Keep listening
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user