Sha256: edfbfee27f53a2ab1388b01a58966c8a58cc59ffe8b852faf7c9606982b8b437
Contents?: true
Size: 585 Bytes
Versions: 2
Compression:
Stored size: 585 Bytes
Contents
require 'faraday' require 'json' module Terminal module ResponseExt class RaiseErrorFromJson < Faraday::Response::Middleware 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 end end end Faraday::Response.register_middleware :raise_error_from_json => Terminal::ResponseExt::RaiseErrorFromJson
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cc-terminal-0.1.4 | lib/terminal/response/raise_error_from_json.rb |
cc-terminal-0.1.2 | lib/terminal/response/raise_error_from_json.rb |