Skip to content

Commit

Permalink
Merge pull request #276 from fablabbcn/bugfix/dont-500-on-non-existen…
Browse files Browse the repository at this point in the history
…t-components-for-readings

Return something sensible when searching readings for non-existent components
  • Loading branch information
oscgonfer authored Oct 27, 2023
2 parents 983926e + 2a4fb7f commit 9d37ef2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/kairos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ def self.query params

component = device.find_component_by_sensor_id(sensor_id)

unless component
return {
device_id: params[:id],
sensor_key: sensor_key,
sensor_id: sensor_id,
component_id: nil,
rollup: params[:rollup],
function: function,
from: params[:from],
to: params[:to],
sample_size: 0,
readings: [],
}
end

metrics = [{
tags: { device_id: params[:id] },
Expand Down

0 comments on commit 9d37ef2

Please sign in to comment.