Exception: ApiaClient::RequestError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, status, body) ⇒ RequestError

rubocop:disable Lint/MissingSuper



10
11
12
13
14
15
16
# File 'lib/apia_client/errors/request_error.rb', line 10

def initialize(client, status, body)
  @client = client
  @status = status
  @body = body

  @error = @body['error']
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/apia_client/errors/request_error.rb', line 7

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/apia_client/errors/request_error.rb', line 6

def status
  @status
end

Instance Method Details

#codeObject



31
32
33
34
35
# File 'lib/apia_client/errors/request_error.rb', line 31

def code
  return if @error.nil?

  @error['code']
end

#descriptionObject



37
38
39
40
41
# File 'lib/apia_client/errors/request_error.rb', line 37

def description
  return if @error.nil?

  @error['description']
end

#detailObject



43
44
45
46
47
# File 'lib/apia_client/errors/request_error.rb', line 43

def detail
  return if @error.nil?

  @error['detail'] || {}
end

#to_sObject

rubocop:enable Lint/MissingSuper



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/apia_client/errors/request_error.rb', line 19

def to_s
  string = ["[#{@status}]"]
  if code && description
    string << "#{code}: #{description}"
  elsif code
    string << code
  else
    string << @body
  end
  string.join(' ')
end