Sha256: 0df7e2b492003e6b683f6a8c6ad3e6294353b1cd4832462f86056923ebc87011
Contents?: true
Size: 840 Bytes
Versions: 2
Compression:
Stored size: 840 Bytes
Contents
module ActionKitRest module Response class RaiseError < Faraday::Response::Middleware def on_complete(response) status_code = response[:status].to_i if (400...600).include? status_code if status_code == 400 raise ActionKitRest::Response::ValidationError.new(url: response[:url].to_s, body: response[:body]) elsif status_code == 404 raise ActionKitRest::Response::NotFound.new(response[:url].to_s) else raise StandardError.new(error_message(response)) end end end def error_message(response) "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} \n\n #{response[:body] if response[:body]}" end end class NotFound < StandardError ; end end # Response::RaiseError end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
action_kit_rest-0.2.2 | lib/action_kit_rest/response/raise_error.rb |
action_kit_rest-0.2.1 | lib/action_kit_rest/response/raise_error.rb |