Class: LinkedIn::RaiseError

Inherits:
Faraday::Response::RaiseError
  • Object
show all
Defined in:
lib/linked_in/raise_error.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(response) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/linked_in/raise_error.rb', line 5

def on_complete(response)
  data = Mash.from_json(response.body)
  case response.status.to_i
  when 400
    raise LinkedIn::InvalidRequest.new(data), "(#{data.status}): #{data.message}"
  when 401
    raise LinkedIn::UnauthorizedError.new(data), "(#{data.status}): #{data.message}"
  when 403
    raise LinkedIn::AccessDeniedError.new(data), "(#{data.status}): #{data.message}"
  when 404
    raise LinkedIn::NotFoundError.new(data), "(#{data.status}): #{data.message}"
  when 500
    raise LinkedIn::InformLinkedInError.new(data), "LinkedIn had an internal error. (#{data.status}): #{data.message}"
  when 502..504
    raise LinkedIn::UnavailableError.new(data), "(#{data.status}): #{data.message}"
  else
    super
  end
end