Skip to content

Commit

Permalink
Merge pull request #261 from fablabbcn/bugfix/better-error-logging-fo…
Browse files Browse the repository at this point in the history
…r-json-errors-in-mqtt-handler

add extra logging for mqtt message handler JSON errors
  • Loading branch information
oscgonfer authored Oct 10, 2023
2 parents 423f695 + 02f0ccd commit 7a1e18e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/lib/mqtt_messages_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ def self.handle_topic(topic, message)
elsif topic.to_s.include?('readings')
handle_readings(device, message)
elsif topic.to_s.include?('info')
device.update hardware_info: JSON.parse(message)
begin
json_info = JSON.parse(message)
rescue Exception => e
e.message << "\nmessage: #{message}"
raise e
end
device.update hardware_info: json_info
end
end

Expand Down Expand Up @@ -51,7 +57,12 @@ def self.parse_raw_readings(message)
reading['data'].first['sensors'] << { 'id' => raw_id, 'value' => raw_value }
end

JSON[reading]
begin
JSON[reading]
rescue Exception => e
e.message << "\nreading: #{reading}"
raise e
end
end

def self.handle_hello(orphan_device)
Expand Down

0 comments on commit 7a1e18e

Please sign in to comment.