Exception: IbmAppconfigurationRubySdk::APIError

Inherits:
Error
  • Object
show all
Defined in:
lib/ibm_appconfiguration_ruby_sdk/errors.rb

Overview

Raised for HTTP-level errors returned by the App Configuration service. Carries the HTTP status code and raw response body so callers can inspect the failure detail without parsing the exception message.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, http_status: nil, http_body: nil) ⇒ APIError

Returns a new instance of APIError.

Parameters:

  • msg (String) (defaults to: nil)

    Human-readable error message

  • http_status (Integer, nil) (defaults to: nil)

    HTTP status code

  • http_body (String, nil) (defaults to: nil)

    Raw response body



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

def initialize(msg = nil, http_status: nil, http_body: nil)
  super(msg)
  @http_status = http_status
  @http_body   = http_body
end

Instance Attribute Details

#http_bodyObject (readonly)

Returns the value of attribute http_body.



32
33
34
# File 'lib/ibm_appconfiguration_ruby_sdk/errors.rb', line 32

def http_body
  @http_body
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



32
33
34
# File 'lib/ibm_appconfiguration_ruby_sdk/errors.rb', line 32

def http_status
  @http_status
end

Class Method Details

.from_status(status, body: nil, message: nil) ⇒ APIError

Factory — returns the most specific APIError subclass for the given status.

Parameters:

  • status (Integer)

    HTTP status code

  • body (String, nil) (defaults to: nil)

    Raw response body

  • message (String, nil) (defaults to: nil)

    Override message (defaults to "HTTP ")

Returns:

  • (APIError)

    An instance of the appropriate subclass



50
51
52
53
54
55
56
57
58
59
# File 'lib/ibm_appconfiguration_ruby_sdk/errors.rb', line 50

def self.from_status(status, body: nil, message: nil)
  klass = case status
          when 401        then AuthenticationError
          when 429        then RateLimitError
          when 400, 422   then InvalidRequestError
          when 500..599   then ServerError
          else                 APIError
          end
  klass.new(message || "HTTP #{status}", http_status: status, http_body: body)
end