Exception: CouchRest::Exception

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/couchrest/exceptions.rb

Overview

This is the base CouchRest exception class. Rescue it if you want to catch any exception that your request might raise. You can get the status code by e.http_code, or see anything about the response via e.response. For example, the entire result body (which is probably an HTML error page) is e.response.

Direct Known Subclasses

RequestFailed

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ Exception

Returns a new instance of Exception.



46
47
48
49
# File 'lib/couchrest/exceptions.rb', line 46

def initialize response = nil
  @response = response
  @message = nil
end

Instance Attribute Details

#messageObject



72
73
74
# File 'lib/couchrest/exceptions.rb', line 72

def message
  @message || self.class.default_message
end

#responseObject

Returns the value of attribute response.



43
44
45
# File 'lib/couchrest/exceptions.rb', line 43

def response
  @response
end

Class Method Details

.default_messageObject



76
77
78
# File 'lib/couchrest/exceptions.rb', line 76

def self.default_message
  self.name
end

Instance Method Details

#http_bodyObject



60
61
62
# File 'lib/couchrest/exceptions.rb', line 60

def http_body
  @response.body if @response
end

#http_codeObject



51
52
53
54
# File 'lib/couchrest/exceptions.rb', line 51

def http_code
  # return integer for compatibility
  @response.status if @response
end

#http_headersObject



56
57
58
# File 'lib/couchrest/exceptions.rb', line 56

def http_headers
  @response.headers if @response
end

#inspectObject



64
65
66
# File 'lib/couchrest/exceptions.rb', line 64

def inspect
  "#{message}: #{http_body}"
end

#to_sObject



68
69
70
# File 'lib/couchrest/exceptions.rb', line 68

def to_s
  inspect
end