From 48cdd4b1ee0685674aa998d4daa295656d80ead3 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 22 Sep 2016 11:07:47 +0200 Subject: feature: 502 on ConnectionErrors If one source raises a 502 and no other handler has any result we'll respond with a 502 - bad gateway. --- lib/nickserver/dispatcher.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/nickserver/dispatcher.rb b/lib/nickserver/dispatcher.rb index 75f6083..869f721 100644 --- a/lib/nickserver/dispatcher.rb +++ b/lib/nickserver/dispatcher.rb @@ -24,6 +24,7 @@ require 'nickserver/request_handlers/fingerprint_handler' module Nickserver class Dispatcher + def initialize(responder) @responder = responder end @@ -45,12 +46,26 @@ module Nickserver end def handler_chain - HandlerChain.new RequestHandlers::InvalidEmailHandler, + @handler_chain ||= init_handler_chain + end + + def init_handler_chain + chain = HandlerChain.new RequestHandlers::InvalidEmailHandler, RequestHandlers::LocalEmailHandler, RequestHandlers::LeapEmailHandler, RequestHandlers::HkpEmailHandler, RequestHandlers::FingerprintHandler, + Proc.new {|_req| proxy_error_response }, Proc.new { Nickserver::Response.new(404, "404 Not Found\n") } + chain.continue_on HTTP::ConnectionError + return chain + end + + def proxy_error_response + exception = handler_chain.rescued_exceptions.first + if exception + Nickserver::Response.new(502, exception.to_s) + end end def send_response(response) -- cgit v1.2.3