mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-25 20:46:21 +00:00
fix: gestionar las excepciones desde un solo lugar #15564
This commit is contained in:
parent
9d71c5fa0c
commit
30f2f0a442
4 changed files with 21 additions and 17 deletions
|
@ -12,10 +12,6 @@ class ApplicationController < ActionController::Base
|
|||
before_action :notify_unconfirmed_email, unless: :devise_controller?
|
||||
around_action :set_locale
|
||||
|
||||
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
||||
rescue_from ActionController::RoutingError, with: :page_not_found
|
||||
rescue_from ActionController::ParameterMissing, with: :page_not_found
|
||||
|
||||
before_action do
|
||||
Rack::MiniProfiler.authorize_request if current_usuarie&.email&.ends_with?('@' + ENV.fetch('SUTTY', 'sutty.nl'))
|
||||
end
|
||||
|
@ -75,18 +71,6 @@ class ApplicationController < ActionController::Base
|
|||
I18n.with_locale(current_locale, &action)
|
||||
end
|
||||
|
||||
# Muestra una página 404
|
||||
#
|
||||
# @see {https://github.com/rails/rails/issues/25106}
|
||||
def page_not_found
|
||||
self.response_body = nil
|
||||
@_response_body = nil
|
||||
|
||||
headers.delete('Location')
|
||||
|
||||
render 'application/page_not_found', status: :not_found
|
||||
end
|
||||
|
||||
# Necesario para poder acceder a Blazer. Solo les usuaries de este
|
||||
# sitio pueden acceder al panel.
|
||||
def require_usuarie
|
||||
|
|
|
@ -12,13 +12,31 @@ module ExceptionHandler
|
|||
rescue_from PageNotFound, with: :page_not_found
|
||||
rescue_from ActionController::RoutingError, with: :page_not_found
|
||||
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
||||
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
||||
rescue_from ActionController::RoutingError, with: :page_not_found
|
||||
rescue_from ActionController::ParameterMissing, with: :page_not_found
|
||||
end
|
||||
|
||||
def site_not_found
|
||||
reset_response!
|
||||
|
||||
flash[:error] = I18n.t('errors.site_not_found')
|
||||
|
||||
redirect_to sites_path
|
||||
end
|
||||
|
||||
def page_not_found
|
||||
send_file Rails.root.join('public', '404.html')
|
||||
reset_response!
|
||||
|
||||
render 'application/page_not_found', status: :not_found
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def reset_response!
|
||||
self.response_body = nil
|
||||
@_response_body = nil
|
||||
|
||||
headers.delete('Location')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -390,6 +390,7 @@ en:
|
|||
lang:
|
||||
not_available: "This language is not yet available, would you help us by translating Sutty into it?"
|
||||
errors:
|
||||
site_not_found: "Site not found, or maybe you don't have access to it."
|
||||
argument_error: 'Argument `%{argument}` must be an instance of %{class}'
|
||||
unknown_locale: 'Unknown %{locale} locale'
|
||||
posts:
|
||||
|
|
|
@ -389,6 +389,7 @@ es:
|
|||
lang:
|
||||
not_available: "Este idioma todavía no está disponible, ¿nos ayudas a agregarlo y mantenerlo?"
|
||||
errors:
|
||||
site_not_found: "No encontramos ese sitio o quizás no tengas acceso."
|
||||
argument_error: 'El argumento `%{argument}` debe ser una instancia de %{class}'
|
||||
unknown_locale: 'El idioma %{locale} es desconocido'
|
||||
posts:
|
||||
|
|
Loading…
Reference in a new issue