Exception: Google::Cloud::Error

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

Overview

Base google-cloud exception class.

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil) ⇒ Error

Construct a new Google::Cloud::Error object, optionally passing in a message.

Parameters:

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

    an error message



28
29
30
# File 'lib/google/cloud/errors.rb', line 28

def initialize msg = nil
  super
end

Instance Method Details

#bodyObject?

Returns the value of body from the underlying cause error object, if both are present. Otherwise returns nil.

This is typically present on errors originating from calls to an API over HTTP/REST.

Returns:

  • (Object, nil)


53
54
55
56
# File 'lib/google/cloud/errors.rb', line 53

def body
  return nil unless cause.respond_to? :body
  cause.body
end

#codeObject?

Returns the value of code from the underlying cause error object, if both are present. Otherwise returns nil.

This is typically present on errors originating from calls to an API over gRPC.

Returns:

  • (Object, nil)


79
80
81
82
# File 'lib/google/cloud/errors.rb', line 79

def code
  return nil unless cause.respond_to? :code
  cause.code
end

#detailsObject?

Returns the value of details from the underlying cause error object, if both are present. Otherwise returns nil.

This is typically present on errors originating from calls to an API over gRPC.

Returns:

  • (Object, nil)


92
93
94
95
# File 'lib/google/cloud/errors.rb', line 92

def details
  return nil unless cause.respond_to? :details
  cause.details
end

#domainObject?

Returns the value of domain from the ::Google::Rpc::ErrorInfo object, if it exists in the status_details array.

This is typically present on errors originating from calls to an API over gRPC.

Returns:

  • (Object, nil)


154
155
156
157
# File 'lib/google/cloud/errors.rb', line 154

def domain
  return nil unless error_info.respond_to? :domain
  error_info.domain
end

#error_info::Google::Rpc::ErrorInfo?

Returns the ::Google::Rpc::ErrorInfo object present in the status_details or details array, given that the following is true:

  • either status_details or details exists and is an array
  • there is exactly one ::Google::Rpc::ErrorInfo object in that array. Looks in status_details first, then in details.

Returns:

  • (::Google::Rpc::ErrorInfo, nil)


131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/google/cloud/errors.rb', line 131

def error_info
  @error_info ||= begin
    check_property = lambda do |prop|
      if prop.is_a? Array
        error_infos = prop.find_all { |status| status.is_a?(::Google::Rpc::ErrorInfo) }
        if error_infos.length == 1
          error_infos[0]
        end
      end
    end

    check_property.call(status_details) || check_property.call(details)
  end
end

#error_metadataHash?

Returns the value of metadata from the ::Google::Rpc::ErrorInfo object, if it exists in the status_details array.

This is typically present on errors originating from calls to an API over gRPC.

Returns:

  • (Hash, nil)


180
181
182
183
# File 'lib/google/cloud/errors.rb', line 180

def 
  return nil unless error_info.respond_to? :metadata
  error_info..to_h
end

#headerObject?

Returns the value of header from the underlying cause error object, if both are present. Otherwise returns nil.

This is typically present on errors originating from calls to an API over HTTP/REST.

Returns:

  • (Object, nil)


66
67
68
69
# File 'lib/google/cloud/errors.rb', line 66

def header
  return nil unless cause.respond_to? :header
  cause.header
end

#metadataObject?

Returns the value of metadata from the underlying cause error object, if both are present. Otherwise returns nil.

This is typically present on errors originating from calls to an API over gRPC.

Returns:

  • (Object, nil)


105
106
107
108
# File 'lib/google/cloud/errors.rb', line 105

def 
  return nil unless cause.respond_to? :metadata
  cause.
end

#reasonObject?

Returns the value of reason from the ::Google::Rpc::ErrorInfo object, if it exists in the status_details array.

This is typically present on errors originating from calls to an API over gRPC.

Returns:

  • (Object, nil)


167
168
169
170
# File 'lib/google/cloud/errors.rb', line 167

def reason
  return nil unless error_info.respond_to? :reason
  error_info.reason
end

#status_codeObject?

Returns the value of status_code from the underlying cause error object, if both are present. Otherwise returns nil.

This is typically present on errors originating from calls to an API over HTTP/REST.

Returns:

  • (Object, nil)


40
41
42
43
# File 'lib/google/cloud/errors.rb', line 40

def status_code
  return nil unless cause.respond_to? :status_code
  cause.status_code
end

#status_detailsObject?

Returns the value of status_details from the underlying cause error object, if both are present. Otherwise returns nil.

This is typically present on errors originating from calls to an API over gRPC.

Returns:

  • (Object, nil)


118
119
120
121
# File 'lib/google/cloud/errors.rb', line 118

def status_details
  return nil unless cause.respond_to? :status_details
  cause.status_details
end