Class: Insights::API::Common::CustomExceptions

Inherits:
Object
  • Object
show all
Defined in:
lib/insights/api/common/custom_exceptions.rb

Constant Summary collapse

CUSTOM_EXCEPTION_LIST =
%w[Pundit::NotAuthorizedError].freeze

Class Method Summary collapse

Class Method Details

.custom_message(exception) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/insights/api/common/custom_exceptions.rb', line 7

def self.custom_message(exception)
  case exception.class.to_s
  when "Pundit::NotAuthorizedError"
    exception.policy.try(:error_message) ||
      "You are not authorized to perform the #{exception.query.to_s.delete_suffix('?')} action for this #{exception.record.model_name.human.downcase}"
  end
end