Class: Tinybucket::Response::Handler

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/tinybucket/response/handler.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tinybucket/response/handler.rb', line 6

def on_complete(env)
  status_code = env[:status].to_i

  return if status_code < 400

  case status_code
  when 404
    raise Tinybucket::Error::NotFound.new(env)
  when 409
    raise Tinybucket::Error::Conflict.new(env)
  else
    Tinybucket.logger.error "Invalid response code:#{status_code}"
    raise Tinybucket::Error::ServiceError.new(env)
  end
end