5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 15:46:22 +00:00
panel/app/controllers/concerns/exception_handler.rb

59 lines
1.4 KiB
Ruby
Raw Normal View History

# 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
included do
rescue_from SiteNotFound, with: :site_not_found
2020-08-29 23:21:45 +00:00
rescue_from PageNotFound, 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(exception)
reset_response!
flash[:error] = I18n.t('errors.site_not_found')
ExceptionNotifier.notify_exception(exception)
redirect_to sites_path
end
2020-08-29 23:21:45 +00:00
def page_unauthorized(exception)
reset_response!
flash[:error] = I18n.t('errors.page_unauthorized')
ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie.id })
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
def reset_response!
self.response_body = nil
@_response_body = nil
headers.delete('Location')
2020-08-29 23:21:45 +00:00
end
end