Class: Librato::Metrics::Middleware::ExpectsStatus

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/librato/metrics/middleware/expects_status.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/librato/metrics/middleware/expects_status.rb', line 7

def on_complete(env)
  # TODO: make exception output prettier
  case env[:status]
  when 401
    raise Unauthorized.new(env.to_s, env)
  when 403
    raise Forbidden.new(env.to_s, env)
  when 404
    raise NotFound.new(env.to_s, env)
  when 422
    raise EntityAlreadyExists.new(env.to_s, env)
  when 400..499
    raise ClientError.new(env.to_s, env)
  when 500..599
    raise ServerError.new(env.to_s, env)
  end
end