Class: ActionController::Twirp::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/action_controller/twirp/error.rb

Overview

Class to generate Twirp::Error from an exception class and Config

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ Error

Returns a new instance of Error.

Parameters:

  • content (Exception)

    given as a value of :twirp_error key of render method.



10
11
12
13
14
15
16
# File 'lib/action_controller/twirp/error.rb', line 10

def initialize(exception)
  unless exception.is_a?(Exception)
    raise ArgumentError, 'Instance of Exception class can be specified'
  end

  @exception = exception
end

Instance Method Details

#generateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/action_controller/twirp/error.rb', line 18

def generate
  if Config.exception_codes.key?(exception_name)
    code = Config.exception_codes[exception_name]
    message = Config.build_message.call(exception)
     = Config..call(exception)

    ::Twirp::Error.public_send(code, message, )
  else
    ::Twirp::Error.internal_with(exception)
  end
rescue StandardError => e
  ::Twirp::Error.internal_with(e)
end