samvera / hyrax

Hyrax is a Ruby on Rails Engine built by the Samvera community. Hyrax provides a foundation for creating many different digital repository applications.
http://hyrax.samvera.org/
Apache License 2.0
185 stars 124 forks source link

Improved Matomo error response handling #6920

Closed iccole closed 1 month ago

iccole commented 1 month ago

Descriptive summary

Matomo doesn't report API errors through status codes. It returns errors in the form of: {"result":"error","message":"error message"}

The current matomo integration checks for http status codes and will fail when trying to parse the matomo error response.

Steps to reproduce the behavior in User Interface (UI)

Preconditions:

  1. Have Matomo fail, or spin up your own fake 'matomo' service
  2. Configure Matomo as the HYRAX_ANALYTICS_PROVIDER
  3. Create an admin user

To see the error behavior:

  1. As the admin user, navigate to the dashboard

Actual behavior

An ActionView::Template::Error is thrown

app-1  | [a1f83798-3dd0-487d-8e18-507de12cbc3f] ActionView::Template::Error (invalid date):
app-1  | [a1f83798-3dd0-487d-8e18-507de12cbc3f]     1: <div id="user-activity" class="col-md-9" aria-hidden="true" style="height: 200px">
app-1  | [a1f83798-3dd0-487d-8e18-507de12cbc3f]     2:   <% users = Hyrax::Admin::UserActivityPresenter.new(@start_date.to_date,@end_date.to_date).as_json %>
app-1  | [a1f83798-3dd0-487d-8e18-507de12cbc3f]     3:   <% return_visits = Hyrax::Analytics.returning_visits_by_day("#{@start_date},#{@end_date}").list.reverse %>
app-1  | [a1f83798-3dd0-487d-8e18-507de12cbc3f]     4:   <% new_visits = Hyrax::Analytics.new_visits_by_day("#{@start_date},#{@end_date}").list.reverse %>
---

Acceptance Criteria/Expected Behavior

Rationale (for feature request only)

Parsing the API response for an error result feels relatively fragile but there doesn't seem to intent to change the pattern - see https://matomo.org/faq/how-to/faq_20278/ and https://github.com/matomo-org/matomo/issues/18851. Additionally, with the existing behavior the dashboard will crash rendering it unusable on the few occasions our matomo service has been down.