Module: Pundit::Plus::CustomException

Defined in:
lib/pundit/plus/custom_exception.rb

Overview

This module is prepended to Pundit to allow for custom exceptions to be raised by policies.

Instance Method Summary collapse

Instance Method Details

#raise(klass, query:, record:, policy:) ⇒ Object

This method is called by Pundit when a policy raises an exception.

The default implementation raises the exception that was passed to ‘authorize`, but you can override this method in your policy classes to handle the exception differently.

To make use of this method define the ‘exception_from` method in your policy class.



18
19
20
# File 'lib/pundit/plus/custom_exception.rb', line 18

def raise(klass, query:, record:, policy:)
  super(policy.exception_from(query:), query: query, record: record, policy: policy)
end