Sha256: 5a9c62d5cc8fccf2218960e10875c4c78a0dcbb4c22f3e35a132e6ac49961266

Contents?: true

Size: 675 Bytes

Versions: 3

Compression:

Stored size: 675 Bytes

Contents

require 'faraday'

# @private
module Faraday
  # @private
  class Response::RaiseHttp5xx < Response::Middleware

    def on_complete(env)
      case env[:status].to_i
      when 500
        raise Genability::ServerError, error_message(env, "Something is wrong on our end. If the problem persists please file a bug report or contact support.")
      when 503
        raise Genability::ServiceUnavailable, error_message(env, "The Genability API is down, please try again later.")
      end
    end

    private

    def error_message(env, body=nil)
      "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')}"
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
genability-0.3.0 lib/faraday/response/raise_http_5xx.rb
genability-0.2.0 lib/faraday/response/raise_http_5xx.rb
genability-0.1.0 lib/faraday/response/raise_http_5xx.rb