Class: Tatooine::Middleware::RaiseHttpError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/tatooine/middleware/raise_http_error.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tatooine/middleware/raise_http_error.rb', line 4

def on_complete(env)
  case env[:status].to_i
  when 400
    raise Tatooine::BadRequest, response_values(env)
  when 404
    raise Tatooine::NotFound, response_values(env)
  when 500
    raise Tatooine::InternalServerError, response_values(env)
  when 502
    raise Tatooine::BadGateway, response_values(env)
  when 503
    raise Tatooine::ServiceUnavailable, response_values(env)
  when 504
    raise Tatooine::GatewayTimeout, response_values(env)
  when 521
    raise Tatooine::OriginDown, response_values(env)
  end
end

#response_values(env) ⇒ Object



23
24
25
# File 'lib/tatooine/middleware/raise_http_error.rb', line 23

def response_values(env)
  {:status => env.status, :headers => env.response_headers, :body => env.body}
end