Sha256: 7acbd70e80037f4e3cf62f2596455bc0c3686bf55f59e0d4d4019f546b068ff2

Contents?: true

Size: 614 Bytes

Versions: 7

Compression:

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

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
saddle-0.0.53 lib/saddle/middleware/response/default_response.rb
saddle-0.0.51 lib/saddle/middleware/response/default_response.rb
saddle-0.0.50 lib/saddle/middleware/response/default_response.rb
saddle-0.0.49 lib/saddle/middleware/response/default_response.rb
saddle-0.0.48 lib/saddle/middleware/response/default_response.rb
saddle-0.0.46 lib/saddle/middleware/response/default_response.rb
saddle-0.0.45 lib/saddle/middleware/response/default_response.rb