mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-25 23:36:23 +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?
|
before_action :notify_unconfirmed_email, unless: :devise_controller?
|
||||||
around_action :set_locale
|
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
|
before_action do
|
||||||
Rack::MiniProfiler.authorize_request if current_usuarie&.email&.ends_with?('@' + ENV.fetch('SUTTY', 'sutty.nl'))
|
Rack::MiniProfiler.authorize_request if current_usuarie&.email&.ends_with?('@' + ENV.fetch('SUTTY', 'sutty.nl'))
|
||||||
end
|
end
|
||||||
|
@ -75,18 +71,6 @@ class ApplicationController < ActionController::Base
|
||||||
I18n.with_locale(current_locale, &action)
|
I18n.with_locale(current_locale, &action)
|
||||||
end
|
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
|
# Necesario para poder acceder a Blazer. Solo les usuaries de este
|
||||||
# sitio pueden acceder al panel.
|
# sitio pueden acceder al panel.
|
||||||
def require_usuarie
|
def require_usuarie
|
||||||
|
|
|
@ -12,13 +12,31 @@ module ExceptionHandler
|
||||||
rescue_from PageNotFound, with: :page_not_found
|
rescue_from PageNotFound, with: :page_not_found
|
||||||
rescue_from ActionController::RoutingError, 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 Pundit::NilPolicyError, with: :page_not_found
|
||||||
|
rescue_from ActionController::RoutingError, with: :page_not_found
|
||||||
|
rescue_from ActionController::ParameterMissing, with: :page_not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
def site_not_found
|
def site_not_found
|
||||||
|
reset_response!
|
||||||
|
|
||||||
|
flash[:error] = I18n.t('errors.site_not_found')
|
||||||
|
|
||||||
redirect_to sites_path
|
redirect_to sites_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_not_found
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -390,6 +390,7 @@ en:
|
||||||
lang:
|
lang:
|
||||||
not_available: "This language is not yet available, would you help us by translating Sutty into it?"
|
not_available: "This language is not yet available, would you help us by translating Sutty into it?"
|
||||||
errors:
|
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}'
|
argument_error: 'Argument `%{argument}` must be an instance of %{class}'
|
||||||
unknown_locale: 'Unknown %{locale} locale'
|
unknown_locale: 'Unknown %{locale} locale'
|
||||||
posts:
|
posts:
|
||||||
|
|
|
@ -389,6 +389,7 @@ es:
|
||||||
lang:
|
lang:
|
||||||
not_available: "Este idioma todavía no está disponible, ¿nos ayudas a agregarlo y mantenerlo?"
|
not_available: "Este idioma todavía no está disponible, ¿nos ayudas a agregarlo y mantenerlo?"
|
||||||
errors:
|
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}'
|
argument_error: 'El argumento `%{argument}` debe ser una instancia de %{class}'
|
||||||
unknown_locale: 'El idioma %{locale} es desconocido'
|
unknown_locale: 'El idioma %{locale} es desconocido'
|
||||||
posts:
|
posts:
|
||||||
|
|
Loading…
Reference in a new issue