Exception: RequestError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/frecon/request_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, message = nil, context = nil) ⇒ RequestError

Returns a new instance of RequestError.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/frecon/request_error.rb', line 15

def initialize(code, message = nil, context = nil)
  @code = code
  @message = message
  @context = context

  # When @message is a String or an Array,
  # the return_value is set to a Sinatra-compliant
  # Array with @code being the first element and the
  # response body being the stringification of the
  # JSON stringification of @context and @message.
  #
  # If @message is a String, it is first put into an
  # array.
  #
  # If @message is neither a String nor an Array,
  # @return_value becomes simply @code.
  @return_value =
    case @message
    when String
      [@code, JSON.generate({ context: @context, errors: [ @message ] })]
    when Array
      [@code, JSON.generate({ context: @context, errors: @message })]
    else
      @code
    end
end

Instance Attribute Details

#return_valueObject (readonly)

Returns the value of attribute return_value.



13
14
15
# File 'lib/frecon/request_error.rb', line 13

def return_value
  @return_value
end