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 8e2aed4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/helpers/subdomains_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module SubdomainsHelper

def registered_subdomain
Subdomain.find(app_subdomain)
rescue ActiveRecord::RecordNotFound
rescue StaticApplicationRecord::EntryNotFound
nil
end

Expand Down
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 8e2aed4

Please sign in to comment.