Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make exceptions in the mqtt message handler more... noticeable. #24

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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