Sha256: 47924289819e3da7eb7042cb884048f58c4e4e352e35a035fe1c7356722f2c7a

Contents?: true

Size: 642 Bytes

Versions: 13

Compression:

Stored size: 642 Bytes

Contents

require 'faraday'



module Saddle
  module Middleware
    module Response

      # Public: Returns a default response in the case of an exception
      # Expects default_response to be defined in the request of connection options, otherwise rethrows exception
      class DefaultResponse < Faraday::Middleware
        def call(env)
          begin
            @app.call(env)
          rescue Faraday::Error::ClientError
            if res = env[:request][:default_response]
              return ::Faraday::Response.new(:body => res)
            else
              raise
            end
          end
        end
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
saddle-0.0.44 lib/saddle/middleware/response/default_response.rb
saddle-0.0.43 lib/saddle/middleware/response/default_response.rb
saddle-0.0.42 lib/saddle/middleware/response/default_response.rb
saddle-0.0.41 lib/saddle/middleware/response/default_response.rb
saddle-0.0.38 lib/saddle/middleware/response/default_response.rb
saddle-0.0.37 lib/saddle/middleware/response/default_response.rb
saddle-0.0.36 lib/saddle/middleware/response/default_response.rb
saddle-0.0.35 lib/saddle/middleware/response/default_response.rb
saddle-0.0.34 lib/saddle/middleware/response/default_response.rb
saddle-0.0.33 lib/saddle/middleware/response/default_response.rb
saddle-0.0.32 lib/saddle/middleware/response/default_response.rb
saddle-0.0.31 lib/saddle/middleware/response/default_response.rb
saddle-0.0.30 lib/saddle/middleware/response/default_response.rb