Sha256: d0d39204bc3a9e422070e2838394095333f80f93cd817c5e04a29fe5bccce113

Contents?: true

Size: 689 Bytes

Versions: 1

Compression:

Stored size: 689 Bytes

Contents

require 'faraday'
require 'faraday_middleware'

module TN
  module HTTP
    ClientError = Class.new(Faraday::ClientError)

    class WrapError < Faraday::Middleware
      def call(env)
        @app.call(env)
      rescue Faraday::ClientError => e
        raise ClientError.new(e)
      end
    end

    def self.default_connection
      Faraday.new do |conn|
        conn.use TN::HTTP::WrapError
        yield conn if block_given?
        conn.adapter Faraday.default_adapter
      end
    end

    def self.default_json_connection
      default_connection do |conn|
        conn.response :mashify
        conn.response :json
        yield conn if block_given?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dino_utils-0.1.7 lib/tn/http.rb