Exception: Gcloud::Pubsub::ApiError

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

Overview

ApiError

Raised when an API call is not successful.

Direct Known Subclasses

AlreadyExistsError, NotFoundError

Instance Attribute Summary

Attributes inherited from Error

#response

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, response) ⇒ ApiError

Returns a new instance of ApiError


58
59
60
61
# File 'lib/gcloud/pubsub/errors.rb', line 58

def initialize message, response
  super message
  @response = response
end

Class Method Details

.klass_for(status) ⇒ Object


71
72
73
74
75
76
77
78
# File 'lib/gcloud/pubsub/errors.rb', line 71

def self.klass_for status
  if status == "ALREADY_EXISTS"
    return AlreadyExistsError
  elsif status == "NOT_FOUND"
    return NotFoundError
  end
  self
end

Instance Method Details

#codeObject

The code of the error.


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

def code
  response.data["error"]["code"]
rescue
  nil
end

#errorsObject

The errors encountered.


52
53
54
55
56
# File 'lib/gcloud/pubsub/errors.rb', line 52

def errors
  response.data["error"]["errors"]
rescue
  []
end