Skip to content

Commit

Permalink
Merge pull request #24 from wiseman/louder_errors
Browse files Browse the repository at this point in the history
Make exceptions in the mqtt message handler more... noticeable.
  • Loading branch information
mchadwick-iqt committed Jan 28, 2022
2 parents 567a221 + b169e48 commit 42885b6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions axis-ptz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,14 @@ def update_config(config):
#############################################
## MQTT Callback Function ##
#############################################

def on_message(client, userdata, message):
try:
return on_message_impl(client, userdata, message)
except Exception as exc:
logging.exception("Error in MQTT message callback: %s", exc)

def on_message_impl(client, userdata, message):
global currentPlane
global object_timeout
global camera_longitude
Expand All @@ -296,13 +303,14 @@ def on_message(client, userdata, message):
#payload = json.loads(messsage.payload) # you can use json.loads to convert string to json
except JSONDecodeError as e:
# do whatever you want
print(e)
logging.exception("Error decoding message as JSON: %s", e)
except TypeError as e:
logging.exception("Error decoding message as JSON: %s", e)
# do whatever you want in this case
print(e)
except ValueError as e:
print(e)
logging.exception("Error decoding message as JSON: %s", e)
except:
logging.exception("Error decoding message as JSON: %s", e)
print("Caught it!")

if message.topic == object_topic:
Expand Down

0 comments on commit 42885b6

Please sign in to comment.