require 'faraday' require 'evrythng/error/bad_gateway' require 'evrythng/error/internal_server_error' require 'evrythng/error/service_unavailable' module Evrythng module Response class RaiseServerError < Faraday::Response::Middleware def on_complete(env) case env[:status].to_i when 500 raise Evrythng::Error::InternalServerError.new("Something is technically wrong.", env[:response_headers]) when 502 raise Evrythng::Error::BadGateway.new("Evrythng is down or being upgraded.", env[:response_headers]) when 503 raise Evrythng::Error::ServiceUnavailable.new("Evrythng is over capacity.", env[:response_headers]) end end end end end