Exception: Jortt::Client::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/jortt/client/error.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, key, message, details) ⇒ Error

Returns a new instance of Error.



15
16
17
18
19
20
21
22
# File 'lib/jortt/client/error.rb', line 15

def initialize(code, key, message, details)
  @code = code
  @key = key
  @message = message
  @details = details

  super(error_message)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/jortt/client/error.rb', line 4

def code
  @code
end

#detailsObject (readonly)

Returns the value of attribute details.



4
5
6
# File 'lib/jortt/client/error.rb', line 4

def details
  @details
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/jortt/client/error.rb', line 4

def key
  @key
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/jortt/client/error.rb', line 4

def message
  @message
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/jortt/client/error.rb', line 4

def response
  @response
end

Class Method Details

.from_response(response) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/jortt/client/error.rb', line 6

def self.from_response(response)
  Error.new(
      response.parsed.dig('error', 'code'),
      response.parsed.dig('error', 'key'),
      response.parsed.dig('error', 'message'),
      response.parsed.dig('error', 'details')
  )
end

Instance Method Details

#error_messageObject



24
25
26
27
28
29
30
# File 'lib/jortt/client/error.rb', line 24

def error_message
  [message].tap do |m|
    details.each do |detail|
      m << "#{detail['param']} #{detail['message']}"
    end
  end.join("\n")
end