Skip to content

Commit

Permalink
Detects returned matomo errors for better response parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
iccole committed Oct 10, 2024
1 parent aeb5e3e commit a7cefc3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/services/hyrax/analytics/matomo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,18 @@ def results_array(response, metric)
Hyrax::Analytics::Results.new(results)
end

# If Matomo detects an error it will return a reponse with the key {"result":"error"}
# instead of returning an error status code. This method checks for that key.
def contains_matomo_error?(response)
response.is_a?(Hash) && response["result"] == "error"
end

def get(params)
response = Faraday.get(config.base_url, params)
return [] if response.status != 200
JSON.parse(response.body)
api_response = JSON.parse(response.body)
return [] if contains_matomo_error?(api_response)
api_response
end

def api_params(method, period, date, additional_params = {})
Expand Down

0 comments on commit a7cefc3

Please sign in to comment.