Sha256: 6abc41bc930a59a43007602c51472259e7b1be316883b4c931b1751f91e63fae

Contents?: true

Size: 606 Bytes

Versions: 14

Compression:

Stored size: 606 Bytes

Contents

require 'faraday'


module Saddle
  module Middleware
    module Response
      class RaiseError < Faraday::Middleware

        def call(env)
          result = @app.call(env)

          case result.status
          when 404
            raise Faraday::Error::ResourceNotFound, response_values(result)
          when 400...600
            raise Faraday::Error::ClientError, response_values(result)
          end

          result
        end

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

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
saddle-0.1.0 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.53 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.51 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.50 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.49 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.48 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.46 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.45 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.44 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.43 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.42 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.41 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.38 lib/saddle/middleware/response/raise_error.rb
saddle-0.0.37 lib/saddle/middleware/response/raise_error.rb