Class: ActionController::Twirp::ErrorRenderer

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

Overview

Convert Twirp::Error to #render option

Instance Method Summary collapse

Constructor Details

#initialize(content, options) ⇒ ErrorRenderer

Returns a new instance of ErrorRenderer.

Parameters:

  • content (Exception)

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

  • options (Hash)

    options of render method.



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

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

  @content = content
  @options = options.dup
end

Instance Method Details

#to_render_optionObject



18
19
20
21
22
23
# File 'lib/action_controller/twirp/error_renderer.rb', line 18

def to_render_option
  {
    json: twirp_error.to_h,
    **@options.merge(status: status, content_type: content_type)
  }
end