Class: ZerigoDNS::Middleware::ErrorHandler

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/zerigodns/middleware/error_handler.rb

Overview

Rasies exceptions on errors

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ ErrorHandler

Constructs new middleware instance



4
5
6
7
# File 'lib/zerigodns/middleware/error_handler.rb', line 4

def initialize app=nil, options={}
  @app = app
  @options = options
end

Instance Method Details

#call(request_env) ⇒ Object

Rasies an exception on a response code that is not HTTP OK



10
11
12
13
14
15
16
17
18
19
# File 'lib/zerigodns/middleware/error_handler.rb', line 10

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