Class: Redd::Response::RaiseError

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/redd/response/raise_error.rb

Overview

Raises the appropriate error when one comes up.

Instance Method Summary collapse

Instance Method Details

#call(faraday) ⇒ Object

Call the middleware.

Parameters:

  • faraday


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/redd/response/raise_error.rb', line 9

def call(faraday)
  @app.call(faraday).on_complete do |env|
    if error = Redd::Error.from_response(env)
      if error == Redd::Error::RateLimited
        time = env.body[:json][:ratelimit]
        fail error.new(env, time)
      else
        fail error.new(env)
      end
    end
  end
end