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.



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

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

Class Method Details

.from_response(resp) ⇒ Object

:nodoc:



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

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



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

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.



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

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

#errorsObject

The errors encountered.



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

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