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.



55
56
57
58
# File 'lib/gcloud/pubsub/errors.rb', line 55

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

Class Method Details

.from_response(resp) ⇒ Object

:nodoc:



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

def self.from_response resp #:nodoc:
  klass = klass_for resp.data["error"]["status"]
  klass.new resp.data["error"]["message"], resp
rescue
  Gcloud::Pubsub::Error.from_response resp
end

.klass_for(status) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/gcloud/pubsub/errors.rb', line 67

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.



41
42
43
44
45
# File 'lib/gcloud/pubsub/errors.rb', line 41

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

#errorsObject

The errors encountered.



49
50
51
52
53
# File 'lib/gcloud/pubsub/errors.rb', line 49

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