diff --git a/app/controllers/concerns/exception_handler.rb b/app/controllers/concerns/exception_handler.rb index 7c1cd540..a47278db 100644 --- a/app/controllers/concerns/exception_handler.rb +++ b/app/controllers/concerns/exception_handler.rb @@ -10,25 +10,41 @@ module ExceptionHandler included do rescue_from SiteNotFound, with: :site_not_found 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::Error, with: :page_not_found + rescue_from Pundit::NotAuthorizedError, with: :page_unauthorized 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 + def site_not_found(exception) reset_response! flash[:error] = I18n.t('errors.site_not_found') + ExceptionNotifier.notify_exception(exception) + redirect_to sites_path end - def page_not_found + def page_unauthorized(exception) reset_response! - render 'application/page_not_found', status: :not_found + flash[:error] = I18n.t('errors.page_unauthorized') + + ExceptionNotifier.notify_exception(exception) + + redirect_to site_path(site) + end + + def page_not_found(exception) + reset_response! + + flash[:error] = I18n.t('errors.page_not_found') + + ExceptionNotifier.notify_exception(exception) + + redirect_to site_path(site) end private diff --git a/config/locales/en.yml b/config/locales/en.yml index ec5b34a9..39054b6f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -397,6 +397,8 @@ en: 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." + page_not_found: "Page not found." + page_unauthorized: "You don't have access to this page, please contact the operators of this site." argument_error: 'Argument `%{argument}` must be an instance of %{class}' unknown_locale: 'Unknown %{locale} locale' posts: diff --git a/config/locales/es.yml b/config/locales/es.yml index 61c645a0..deb193c2 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -396,6 +396,8 @@ es: 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." + page_not_found: "No encontramos esa página." + page_unauthorized: "No tenés acceso a página, para solicitarla, ponete en contacto con les gestores del sitio." argument_error: 'El argumento `%{argument}` debe ser una instancia de %{class}' unknown_locale: 'El idioma %{locale} es desconocido' posts: