Skip to content

Commit

Permalink
Log a warning on DocumentNotFound
Browse files Browse the repository at this point in the history
Log a warning when a `Mongoid::Errors::DocumentNotFound` error is raised
 in a controller. These errors were being silently swallowed by the
 application.

The error occurs when an attempt is made to load a document that doesn't
 exist, which can happen when the overnight DB replication from
 prod->integration fails. It will also happen if the edition ID is
 manipulated in the URL (e.g. in URLs of the form
 `/editions/[edition-id]`), so it's not _necessarily_ an error when it
 happens.
  • Loading branch information
mtaylorgds committed Jul 25, 2024
1 parent b3e3d97 commit 39c461c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def setup_view_paths_for(publication)
prepend_view_path template_folder_for(publication)
end

def record_not_found
def record_not_found(exception)
Rails.logger.warn "Error loading document: #{exception.message}"
render body: { 'raw': "404 Not Found" }, status: :not_found
end

Expand Down

0 comments on commit 39c461c

Please sign in to comment.