Exception: GH::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/gh/error.rb

Direct Known Subclasses

TokenInvalid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error = nil, payload = nil, info = {}) ⇒ Error

Returns a new instance of Error.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gh/error.rb', line 7

def initialize(error = nil, payload = nil, info = {})
  info   = info.merge(error.info) if error.respond_to? :info and Hash === error.info
  error  = error.error while error.respond_to? :error
  @info  = info.merge(:error => error, :payload => payload)

  if error
    set_backtrace error.backtrace if error.respond_to? :backtrace
    if error.respond_to? :response and error.response
      case response = error.response
      when Hash
        @info[:response_status]  = response[:status]
        @info[:response_headers] = response[:headers]
        @info[:response_body]    = response[:body]
      when Faraday::Response
        @info[:response_status]  = response.status
        @info[:response_headers] = response.headers
        @info[:response_body]    = response.body
      else
        @info[:response]         = response
      end
    end
  end
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



5
6
7
# File 'lib/gh/error.rb', line 5

def info
  @info
end

Instance Method Details

#errorObject



35
36
37
# File 'lib/gh/error.rb', line 35

def error
  info[:error]
end

#messageObject



39
40
41
# File 'lib/gh/error.rb', line 39

def message
  "GH request failed\n" + info.map { |k,v| entry(k,v) }.join("\n")
end

#payloadObject



31
32
33
# File 'lib/gh/error.rb', line 31

def payload
  info[:payload]
end