lib/breakers/uptime_middleware.rb in breakers-0.1.1 vs lib/breakers/uptime_middleware.rb in breakers-0.2.0
- old
+ new
@@ -29,16 +29,20 @@
end
protected
def outage_response(outage:, service:)
- Faraday::Response.new.tap do |response|
- response.finish(
- status: 503,
- body: "Outage detected on #{service.name} beginning at #{outage.start_time.to_i}",
- response_headers: {}
- )
+ if Breakers.outage_response[:type] == :status_code
+ Faraday::Response.new.tap do |response|
+ response.finish(
+ status: Breakers.outage_response[:status_code],
+ body: "Outage detected on #{service.name} beginning at #{outage.start_time.to_i}",
+ response_headers: {}
+ )
+ end
+ else
+ raise Breakers::OutageException.new(outage, service)
end
end
def handle_request(service:, request_env:, current_outage: nil)
return @app.call(request_env).on_complete do |response_env|
@@ -58,16 +62,18 @@
plugin.on_success(service, request_env, response_env) if plugin.respond_to?(:on_success)
end
end
end
rescue => e
- handle_error(
- service: service,
- request_env: request_env,
- response_env: nil,
- error: "#{e.class.name} - #{e.message}",
- current_outage: current_outage
- )
+ unless e.is_a?(Breakers::OutageException)
+ handle_error(
+ service: service,
+ request_env: request_env,
+ response_env: nil,
+ error: "#{e.class.name} - #{e.message}",
+ current_outage: current_outage
+ )
+ end
raise
end
def handle_error(service:, request_env:, response_env:, error:, current_outage: nil)
service.add_error