Class: EveOnline::ESI::FaradayMiddlewares::RaiseErrors

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/eve_online/esi/faraday_middlewares/raise_errors.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
# File 'lib/eve_online/esi/faraday_middlewares/raise_errors.rb', line 9

def call(env)
  @app.call(env).on_complete do |environment|
    on_complete(environment)
  end
end

#on_complete(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/eve_online/esi/faraday_middlewares/raise_errors.rb', line 15

def on_complete(env)
  case env[:status]
  when 200
    # HTTP OK
  when 204
    raise EveOnline::Exceptions::NoContent
  when 304
    # HTTP Not Modified
  when 400
    raise EveOnline::Exceptions::BadRequest
  when 401
    raise EveOnline::Exceptions::Unauthorized
  when 403
    raise EveOnline::Exceptions::Forbidden
  when 404
    raise EveOnline::Exceptions::ResourceNotFound
  when 420
    raise EveOnline::Exceptions::ErrorLimited
  when 500
    raise EveOnline::Exceptions::InternalServerError
  when 502
    raise EveOnline::Exceptions::BadGateway
  when 503
    raise EveOnline::Exceptions::ServiceUnavailable
  when 504
    raise EveOnline::Exceptions::GatewayTimeout
  else
    raise "Unknown status: #{env[:status]}"
  end
end