Exception: OCI::Errors::ServiceError

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

Overview

The base error for all requests that return error responses from the service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, service_code, request_id, message) ⇒ ServiceError

Returns a new instance of ServiceError.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oci/errors.rb', line 27

def initialize(status_code, service_code, request_id, message)
  # We need to mask the message attribute here as otherwise we use StandardError's
  # implementation, which calls to_s and so referencing "message" in our to_s in
  # this class would go into an infinite loop

  @message = if message.nil? || message.strip.empty?
               "The service returned error code #{status_code}"
             else
               message.strip
             end

  super @message

  @status_code = status_code
  @service_code = service_code
  @request_id = request_id
end

Instance Attribute Details

#messageString (readonly)

The error message

Returns:

  • (String)


25
26
27
# File 'lib/oci/errors.rb', line 25

def message
  @message
end

#request_idString (readonly)

The request ID, taken from the opc-request-id header.

Returns:

  • (String)


20
21
22
# File 'lib/oci/errors.rb', line 20

def request_id
  @request_id
end

#service_codeString (readonly)

A service-specific error code

Returns:

  • (String)


15
16
17
# File 'lib/oci/errors.rb', line 15

def service_code
  @service_code
end

#status_codeInteger (readonly)

HTTP status code (such as 200 or 404)

Returns:

  • (Integer)


10
11
12
# File 'lib/oci/errors.rb', line 10

def status_code
  @status_code
end

Instance Method Details

#to_sObject



45
46
47
48
# File 'lib/oci/errors.rb', line 45

def to_s
  "{ 'message': '#{message}', 'status': #{status_code}, " \
  "'code': '#{service_code}', 'opc-request-id': '#{request_id}' }"
end