Sha256: 1d1c49b92fa82c1973d68c02aecdb23f36bcc0b9086d38c48e04c708214d8679

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 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 Evrythng::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers])
      when 502
        raise Evrythng::BadGateway.new(error_message(env, "Evrythng is down or being upgraded."), env[:response_headers])
      when 503
        raise Evrythng::ServiceUnavailable.new(error_message(env, "Evrythng 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(' ')} Check http://status.evrythng.net/ for updates on the status of the Evrythng service."
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evrythng-0.0.5 lib/faraday/response/raise_http_5xx.rb