Sha256: 88916696e432f491c83e1420c3c086e04afed0b9e8b810452cfeb53da741a242

Contents?: true

Size: 685 Bytes

Versions: 1

Compression:

Stored size: 685 Bytes

Contents

# Rasies exceptions on errors
class ZerigoDNS::Middleware::ErrorHandler < Faraday::Middleware
  # Constructs new middleware instance
  def initialize app=nil, options={}
    @app = app
    @options = options
  end
  
  # Rasies an exception on a response code that is not HTTP OK
  def call request_env
    @app.call(request_env).on_complete do |response|
      response[:code] = ZerigoDNS::Client::ResponseCode.new(response.status)
      if response[:code].ok?
        response
      else
        raise ZerigoDNS::Client::ResponseError.new(response)
      end
    end
  end
end

Faraday::Response.register_middleware custom_error_handler: lambda {ZerigoDNS::Middleware::ErrorHandler}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zerigodns-1.1.0 lib/zerigodns/middleware/error_handler.rb