Class: Terminal::ResponseExt::RaiseErrorFromJson

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

Instance Method Summary collapse

Instance Method Details

#on_complete(response) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/terminal/response/raise_error_from_json.rb', line 8

def on_complete(response)
  # Terminal.com always returns 200
  code = response.status.to_i

  if code == 200 && response.body[:success] == false || !response.body[:error].nil?
    fail(Terminal::APIResponseError.new(response))
  else
     # How did we get here?
  end
end