ManageIQ/manageiq-api-common

View on GitHub
lib/insights/api/common/custom_exceptions.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Insights
  module API
    module Common
      class CustomExceptions
        CUSTOM_EXCEPTION_LIST = %w[Pundit::NotAuthorizedError].freeze

        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
      end
    end
  end
end