Skip to content

Commit

Permalink
No longer returns ActiveRecord::NotFoundError for static entries
Browse files Browse the repository at this point in the history
With an exception `ActiveRecord::NotFoundError` raised, rails handles
this error within the controller as a 404 error, which seems legit for
these kinds of error.

However, with static content like forms, if we remove or rename/change
forms we don't want to have a 404 error but a 500 error if it happens
(better not to have error ofc, but best case is to catch it and fix it)
  • Loading branch information
skelz0r committed Dec 2, 2024
1 parent 284393e commit 560d13f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/static_application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class StaticApplicationRecord
include ActiveModel::Model
include Draper::Decoratable

class EntryNotFound < StandardError; end

def self.inherited(base)
base.extend ClassMethods

Expand Down Expand Up @@ -34,7 +36,7 @@ def exists?(conditions = {})
end

def find(id)
all.find { |entry| entry.id == id } || fail(ActiveRecord::RecordNotFound, "Couldn't find #{name} with 'id'=#{id}")
all.find { |entry| entry.id == id } || fail(EntryNotFound, "Couldn't find #{name} with 'id'=#{id} within static entries")
end

def values_includes_entry_attribute?(entry, attr, values)
Expand Down

0 comments on commit 560d13f

Please sign in to comment.