fablabbcn / smartcitizen-api

The Smart Citizen Engine
https://developer.smartcitizen.me
GNU Affero General Public License v3.0
10 stars 4 forks source link

Do not 500 when searching for readings for a sensor which does not exist on a device #275

Closed sentry-io[bot] closed 8 months ago

sentry-io[bot] commented 8 months ago

Surfaced in this Sentry Issue: SC-API-15

RuntimeError: JsonNull
  app/models/kairos.rb:107:in `query'
    raise j_body['errors'][0].to_s
  app/controllers/v0/readings_controller.rb:12:in `index'
    render json: Kairos.query(params)
...
(75 additional frame(s) were not displayed)

The problem is that if a component for a given sensor and device doesn't exist, the request is still passed to Kairos, which returns a 500 that percolates through to the user. Instead, we should return a 'sensible' empty response early.