Class: FaradayMiddleware::KnodesErrors

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/faraday/knodes_errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ KnodesErrors

Returns a new instance of KnodesErrors.



18
19
20
21
# File 'lib/faraday/knodes_errors.rb', line 18

def initialize(app)
    super app
    @parser = nil
end

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/faraday/knodes_errors.rb', line 6

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
      when 400
        raise Knodes::BadRequest, response[:body]
        #puts "#{finished_env[:body] if finished_env[:body]}"
      when 404
        raise Knodes::NotFound, response[:body]
        #puts "#{finished_env if finished_env[:body]}"
    end
  end
end