Class: Transifex::Response::RaiseHttpException

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

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/transifex/response/raise_http_exception.rb', line 7

def call(env)
  @app.call(env).on_complete do |response|
    resp = response[:response]
    case response[:status].to_i
    when 401
      raise Transifex::Unauthorized.new(resp)
    when 403
      raise Transifex::Forbidden.new(resp)
    when 404
      raise Transifex::NotFound.new(resp)
    when 406
      raise Transifex::NotAcceptable.new(resp)
    when 409
      raise Transifex::Conflict.new(resp)
    when 415
      raise Transifex::UnsupportedMediaType.new(resp)
    when 422
      raise Transifex::UnprocessableEntity.new(resp)
    end
  end
end