Class: Surveygizmo::Response::RaiseErrorOnFailedRequest

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/surveygizmo/response/raise_error_on_failed_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, klass) ⇒ RaiseErrorOnFailedRequest

Returns a new instance of RaiseErrorOnFailedRequest



16
17
18
19
# File 'lib/surveygizmo/response/raise_error_on_failed_request.rb', line 16

def initialize(app, klass)
  @klass = klass
  super(app)
end

Instance Method Details

#on_complete(env) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/surveygizmo/response/raise_error_on_failed_request.rb', line 7

def on_complete(env)
  if env[:body] && ! env[:body]["result_ok"]
    error_code = env[:body]["code"].to_i
    message = env[:body]["message"]

    raise @klass.new(error_code, message)
  end
end