Exception: Gcloud::Dns::ApiError

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

Overview

Raised when an API call is not successful.

Instance Attribute Summary collapse

Attributes inherited from Error

#inner

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Error

from_error, klass_for

Constructor Details

#initialize(message, code, errors = []) ⇒ ApiError

Returns a new instance of ApiError.



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

def initialize message, code, errors = []
  super message
  @code   = code
  @errors = errors
end

Instance Attribute Details

#codeObject (readonly)

The code of the error.



30
31
32
# File 'lib/gcloud/dns/errors.rb', line 30

def code
  @code
end

#errorsObject (readonly)

The errors encountered.



34
35
36
# File 'lib/gcloud/dns/errors.rb', line 34

def errors
  @errors
end

Class Method Details

.from_response(resp) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/gcloud/dns/errors.rb', line 44

def self.from_response resp
  if resp.data? && resp.data["error"]
    from_response_data resp.data["error"]
  else
    from_response_status resp
  end
end

.from_response_data(error) ⇒ Object



53
54
55
# File 'lib/gcloud/dns/errors.rb', line 53

def self.from_response_data error
  new error["message"], error["code"], error["errors"]
end

.from_response_status(resp) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/gcloud/dns/errors.rb', line 58

def self.from_response_status resp
  if resp.status == 404
    new "#{resp.error_message}: #{resp.request.uri.request_uri}",
        resp.status
  else
    new resp.error_message, resp.status
  end
end