Sha256: e37cd22a7d6d776e66e2ac4241ae784b1df19a2e7873ce3904b5aaf0adb7226b

Contents?: true

Size: 783 Bytes

Versions: 1

Compression:

Stored size: 783 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 Cashstar::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers])
      when 502
        raise Cashstar::BadGateway.new(error_message(env, "Cashstar is down or being upgraded."), env[:response_headers])
      when 503
        raise Cashstar::ServiceUnavailable.new(error_message(env, "(__-){ Cashstar is over capacity."), env[:response_headers])
      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

1 entries across 1 versions & 1 rubygems

Version Path
cashstar-0.1.0 lib/faraday/response/raise_http_5xx.rb