@@ -25,6 +25,8 @@ def show
2525 return unless check_entry_password_protection ( entry )
2626
2727 delegate_to_entry_type_frontend_app! ( entry )
28+ rescue ActiveRecord ::RecordNotFound
29+ render_custom_or_static_404_error_page
2830 end
2931 end
3032 end
@@ -100,15 +102,18 @@ def entry_redirect(entry)
100102 Pageflow . config . public_entry_redirect . call ( entry , request )
101103 end
102104
103- def delegate_to_entry_type_frontend_app! ( entry )
105+ def delegate_to_entry_type_frontend_app! ( entry , override_status : nil )
104106 EntriesControllerEnvHelper . add_entry_info_to_env ( request . env , entry : entry , mode : :published )
105107
106- delegate_to_rack_app! ( entry . entry_type . frontend_app ) do |_status , headers , _body |
108+ delegate_to_rack_app! ( entry . entry_type . frontend_app ) do |result |
109+ status , headers , body = result
107110 config = Pageflow . config_for ( entry )
108111
109112 allow_iframe_for_embed ( headers )
110113 apply_additional_headers ( entry , config , headers )
111114 apply_cache_control ( entry , config , headers )
115+
116+ [ override_status || status , headers , body ]
112117 end
113118 end
114119
@@ -128,5 +133,17 @@ def apply_additional_headers(entry, config, headers)
128133 config . additional_public_entry_headers . for ( entry , request )
129134 )
130135 end
136+
137+ def render_custom_or_static_404_error_page
138+ site = Site . for_request ( request ) . first
139+
140+ if site &.custom_404_entry &.published_without_password_protection?
141+ entry = PublishedEntry . new ( site . custom_404_entry )
142+ delegate_to_entry_type_frontend_app! ( entry , override_status : 404 )
143+ else
144+ # Fallback to ApplicationController's handler method
145+ render_static_404_error_page
146+ end
147+ end
131148 end
132149end
0 commit comments