Module: Kraftwerk::Endpoint::Callable

Defined in:
lib/kraftwerk/endpoint/callable.rb

Overview

Replacement for Hanami::Action::Callable, which does not care about return value of the call method, instead requiring us to assign response via self.body= or via view. We don't want that in Kraftwerk. Return value from #call should be interpreted and returned by the framework.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kraftwerk/endpoint/callable.rb', line 7

def call(env)
  params = Hanami::Action::BaseParams.new(env)
  begin
    response = super(params)
  rescue StandardError => e
    puts e
    puts e.backtrace.join("\n")
    response = Kraftwerk::Response.new(code: 500, body: { error: 'Internal server error' })
  end

  ResponseFormatter.new.call(response: response, params: params)
end