Sha256: 08a8b621e6b96740a5b5fe8ed15a1b1fa66320065460e8df9b83e5e8b5ded706

Contents?: true

Size: 629 Bytes

Versions: 12

Compression:

Stored size: 629 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
            if res = env[:request][:default_response]
              return ::Faraday::Response.new(:body => res)
            else
              raise
            end
          end
        end
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
saddle-0.0.27 lib/saddle/middleware/response/default_response.rb
saddle-0.0.26 lib/saddle/middleware/response/default_response.rb
saddle-0.0.25 lib/saddle/middleware/response/default_response.rb
saddle-0.0.23 lib/saddle/middleware/response/default_response.rb
saddle-0.0.22 lib/saddle/middleware/response/default_response.rb
saddle-0.0.21 lib/saddle/middleware/response/default_response.rb
saddle-0.0.19 lib/saddle/middleware/response/default_response.rb
saddle-0.0.18 lib/saddle/middleware/response/default_response.rb
saddle-0.0.17 lib/saddle/middleware/response/default_response.rb
saddle-0.0.16 lib/saddle/middleware/response/default_response.rb
saddle-0.0.15 lib/saddle/middleware/response/default_response.rb
saddle-0.0.14 lib/saddle/middleware/response/default_response.rb