Sha256: 83301151231371bee13c1696f2760dd26d58a42f2974e4d20da93aacb1f0e852

Contents?: true

Size: 580 Bytes

Versions: 5

Compression:

Stored size: 580 Bytes

Contents

require 'faraday'


module Saddle::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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
saddle-0.0.12 lib/saddle/middleware/response/default_response.rb
saddle-0.0.11 lib/saddle/middleware/response/default_response.rb
saddle-0.0.10 lib/saddle/middleware/response/default_response.rb
saddle-0.0.7 lib/saddle/middleware/response/default_response.rb
saddle-0.0.6 lib/saddle/middleware/response/default_response.rb