Exception: ApiException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/PCP-server-Ruby-SDK/errors/api_exception.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, response_body, cause = nil) ⇒ ApiException

Returns a new instance of ApiException.



4
5
6
7
8
9
# File 'lib/PCP-server-Ruby-SDK/errors/api_exception.rb', line 4

def initialize(status_code, response_body, cause = nil)
  super(response_body)
  @status_code = status_code
  @response_body = response_body
  set_backtrace(cause.backtrace) if cause
end

Instance Attribute Details

#response_bodyObject (readonly)

Returns the value of attribute response_body.



2
3
4
# File 'lib/PCP-server-Ruby-SDK/errors/api_exception.rb', line 2

def response_body
  @response_body
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



2
3
4
# File 'lib/PCP-server-Ruby-SDK/errors/api_exception.rb', line 2

def status_code
  @status_code
end

Instance Method Details

#messageObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/PCP-server-Ruby-SDK/errors/api_exception.rb', line 15

def message
  if @message.nil?
    msg = "Error message: the server returns an error"
  else
    msg = @message
  end

  msg += "\nHTTP status code: #{status_code}" if status_code
  msg += "\nResponse body: #{response_body}" if response_body

  msg
end

#to_sObject



11
12
13
# File 'lib/PCP-server-Ruby-SDK/errors/api_exception.rb', line 11

def to_s
  message
end