2019-07-10 22:07:39 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Gestiona las excepciones que lanzamos desde los controladores
|
|
|
|
module ExceptionHandler
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class SiteNotFound < StandardError; end
|
2020-08-29 23:21:45 +00:00
|
|
|
class PageNotFound < StandardError; end
|
2019-07-10 22:07:39 +00:00
|
|
|
|
|
|
|
included do
|
|
|
|
rescue_from SiteNotFound, with: :site_not_found
|
2020-08-29 23:21:45 +00:00
|
|
|
rescue_from PageNotFound, with: :page_not_found
|
2024-09-05 19:40:19 +00:00
|
|
|
rescue_from Pundit::Error, with: :page_not_found
|
|
|
|
rescue_from Pundit::NotAuthorizedError, with: :page_unauthorized
|
2024-03-14 14:45:33 +00:00
|
|
|
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
|
|
|
rescue_from ActionController::RoutingError, with: :page_not_found
|
|
|
|
rescue_from ActionController::ParameterMissing, with: :page_not_found
|
2019-07-10 22:07:39 +00:00
|
|
|
end
|
|
|
|
|
2024-09-05 19:40:19 +00:00
|
|
|
def site_not_found(exception)
|
2024-03-14 14:45:33 +00:00
|
|
|
reset_response!
|
|
|
|
|
|
|
|
flash[:error] = I18n.t('errors.site_not_found')
|
|
|
|
|
2024-09-05 19:40:19 +00:00
|
|
|
ExceptionNotifier.notify_exception(exception)
|
|
|
|
|
2019-07-10 22:07:39 +00:00
|
|
|
redirect_to sites_path
|
|
|
|
end
|
2020-08-29 23:21:45 +00:00
|
|
|
|
2024-09-05 19:40:19 +00:00
|
|
|
def page_unauthorized(exception)
|
2024-03-14 14:45:33 +00:00
|
|
|
reset_response!
|
|
|
|
|
2024-09-05 19:40:19 +00:00
|
|
|
flash[:error] = I18n.t('errors.page_unauthorized')
|
|
|
|
|
2024-10-14 18:18:51 +00:00
|
|
|
ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie.id })
|
2024-09-05 19:40:19 +00:00
|
|
|
|
|
|
|
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)
|
2024-03-14 14:45:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def reset_response!
|
|
|
|
self.response_body = nil
|
|
|
|
@_response_body = nil
|
|
|
|
|
|
|
|
headers.delete('Location')
|
2020-08-29 23:21:45 +00:00
|
|
|
end
|
2019-07-10 22:07:39 +00:00
|
|
|
end
|