module Hanami::Action::Throwable::ClassMethods

Throw API class methods

@since 0.1.0 @api private

Private Instance Methods

handle_exception(exception) click to toggle source

Handle the given exception with an HTTP status code.

When the exception is raise during call execution, it will be translated into the associated HTTP status.

This is a fine grained control, for a global configuration see Hanami::Action.handled_exceptions

@param exception [Hash] the exception class must be the key and the

HTTP status the value of the hash

@since 0.1.0

@see Hanami::Action.handled_exceptions

@example

require 'hanami/controller'

class Show
  include Hanami::Action
  handle_exception RecordNotFound => 404

  def call(params)
    # ...
    raise RecordNotFound.new
  end
end

Show.new.call({id: 1}) # => [404, {}, ['Not Found']]
# File lib/hanami/action/throwable.rb, line 57
def handle_exception(exception)
  configuration.handle_exception(exception)
end