Sha256: 68209d331c3550778cdb3f1c011e4e601adc78a97823b9ee5bff073870591a1c

Contents?: true

Size: 852 Bytes

Versions: 5

Compression:

Stored size: 852 Bytes

Contents

require 'transifex/error'
require 'faraday_middleware'

module Transifex
  module Response
    class RaiseHttpException < Faraday::Response::Middleware
      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
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
transifex-ruby-0.1.0 lib/transifex/response/raise_http_exception.rb
transifex-ruby-0.0.6 lib/transifex/response/raise_http_exception.rb
transifex-ruby-0.0.5 lib/transifex/response/raise_http_exception.rb
transifex-ruby-0.0.4 lib/transifex/response/raise_http_exception.rb
transifex-ruby-fork-jg-0.1.0 lib/transifex/response/raise_http_exception.rb