Sha256: 9b35ce62125dbf027ff0ea3a948b9754d09587ebd5eacd5280581ac37ca85471

Contents?: true

Size: 541 Bytes

Versions: 5

Compression:

Stored size: 541 Bytes

Contents

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

      def on_complete(response)
        status_code = response[:status].to_i
        if (500...600).include? status_code
          raise Exception.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 < Exception ; end
  end # Response::RaiseError
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vertebrae-0.1.4 lib/response/raise_error.rb
vertebrae-0.1.3 lib/response/raise_error.rb
vertebrae-0.1.2 lib/response/raise_error.rb
vertebrae-0.1.1 lib/response/raise_error.rb
vertebrae-0.1.0 lib/response/raise_error.rb