Exception: PCPServerSDK::Errors::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

The constructor

Parameters:

  • status_code (Integer)
  • response_body (String)
  • cause (StandardError) (defaults to: nil)


12
13
14
15
16
17
# File 'lib/PCP-server-Ruby-SDK/errors/api_exception.rb', line 12

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.



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

def response_body
  @response_body
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



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

def status_code
  @status_code
end

Instance Method Details

#messageObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/PCP-server-Ruby-SDK/errors/api_exception.rb', line 23

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



19
20
21
# File 'lib/PCP-server-Ruby-SDK/errors/api_exception.rb', line 19

def to_s
  message
end