Use controller method for 404 responses

This commit is contained in:
Sebastian Serth
2022-09-14 01:01:14 +02:00
parent 006c794f54
commit f1aa004284
4 changed files with 34 additions and 1 deletions

View File

@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base
before_action :set_sentry_context, :load_embed_options
protect_from_forgery(with: :exception, prepend: true)
rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
rescue_from ActionController::InvalidAuthenticityToken, with: :render_csrf_error
def current_user
@ -68,6 +69,15 @@ class ApplicationController < ActionController::Base
end
private :render_not_authorized
def render_not_found
if current_user&.admin?
render_error t('application.not_found'), :not_found
else
render_not_authorized
end
end
private :render_not_authorized
def render_error(message, status)
set_sentry_context
respond_to do |format|