Exception: Coolsms::RestApi::ResponseError

Inherits:
RequestError show all
Defined in:
lib/coolsms/rest_api/errors.rb

Direct Known Subclasses

EmptyResult, InvalidJson, WrongResponseStatus

Instance Attribute Summary collapse

Attributes inherited from Error

#api

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, cause = $!) ⇒ ResponseError

Returns a new instance of ResponseError.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/coolsms/rest_api/errors.rb', line 43

def initialize(message = nil, cause = $!)
  res = message
  res = message.delete(:response) if message.is_a?(Hash) && message[:response]

  case res
  when Faraday::Response then
    self.status = res.status
    self.headers = res.headers
    self.body = res.body
  when Faraday::Env then
    self.status = res.status
    self.headers = res.response_headers
    self.body = res.body
  when Faraday::Error::ClientError then
    self.status = res[:status]
    self.headers = res[:headers]
    self.body = res[:body]
  end
  
  super(message, cause)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



41
42
43
# File 'lib/coolsms/rest_api/errors.rb', line 41

def body
  @body
end

#headersObject

Returns the value of attribute headers.



41
42
43
# File 'lib/coolsms/rest_api/errors.rb', line 41

def headers
  @headers
end

#statusObject

Returns the value of attribute status.



41
42
43
# File 'lib/coolsms/rest_api/errors.rb', line 41

def status
  @status
end

Class Method Details

.http_statusObject



38
# File 'lib/coolsms/rest_api/errors.rb', line 38

def http_status; 500 end

.statusObject



37
# File 'lib/coolsms/rest_api/errors.rb', line 37

def status; 31000500 end