Exception: FlightStats::API::ResponseError

Inherits:
Error
  • Object
show all
Defined in:
lib/flightstats/api/errors.rb

Overview

The superclass to all errors that occur when making an API request.

Direct Known Subclasses

ClientError, Redirection, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#set_message

Constructor Details

#initialize(request, response) ⇒ ResponseError

Returns a new instance of ResponseError.



11
12
13
# File 'lib/flightstats/api/errors.rb', line 11

def initialize request, response
  @request, @response = request, response
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/flightstats/api/errors.rb', line 8

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



9
10
11
# File 'lib/flightstats/api/errors.rb', line 9

def response
  @response
end

Instance Method Details

#codeObject



15
16
17
# File 'lib/flightstats/api/errors.rb', line 15

def code
  response.code.to_i if response
end

#messageObject



30
31
32
# File 'lib/flightstats/api/errors.rb', line 30

def message
  json and json['error'] and json['error']['errorMessage']
end

#to_sObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/flightstats/api/errors.rb', line 19

def to_s
  if description
    return CGI.unescapeHTML [description, details].compact.join(' ')
  end

  return super unless code
  "%d %s (%s %s)" % [
    code, http_error, request.method, API.base_uri + request.path
  ]
end