Sha256: 5a67428412ab698e76bc33770ee74c36c7560ea70d2f192f1b0a3c2547ae5909

Contents?: true

Size: 549 Bytes

Versions: 7

Compression:

Stored size: 549 Bytes

Contents

module Vertebrae
  module Response
    class RaiseError < Faraday::Response::Middleware

      def on_complete(response)
        status_code = response[:status].to_i
        if (400...600).include? status_code
          raise StandardError.new(error_message(response))
        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

7 entries across 7 versions & 1 rubygems

Version Path
vertebrae-0.3.1 lib/response/raise_error.rb
vertebrae-0.3.0 lib/response/raise_error.rb
vertebrae-0.2.11 lib/response/raise_error.rb
vertebrae-0.2.10 lib/response/raise_error.rb
vertebrae-0.2.9 lib/response/raise_error.rb
vertebrae-0.2.8 lib/response/raise_error.rb
vertebrae-0.2.7 lib/response/raise_error.rb