summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-09-23 15:54:56 +0200
committerAzul <azul@riseup.net>2016-09-23 15:54:56 +0200
commit35433792f9fa23f7b8d9c771d1d3676286a48870 (patch)
treebc9582a8b83f1a8ce22c16e614073dff7aebd9a4
parent906724ff074710c7078b2d8423edd2477283b2e1 (diff)
basic logging and recovery from exceptions raised
-rw-r--r--lib/nickserver/daemon.rb1
-rw-r--r--lib/nickserver/reel_server.rb14
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/nickserver/daemon.rb b/lib/nickserver/daemon.rb
index 9cc1af7..0f9e7bf 100644
--- a/lib/nickserver/daemon.rb
+++ b/lib/nickserver/daemon.rb
@@ -176,6 +176,7 @@ module Nickserver
$stdout.reopen(log_path, 'a')
$stderr.reopen $stdout
$stdout.sync = true
+ $stderr.sync = true
else
# redirect to /dev/null
$stdin.reopen '/dev/null'
diff --git a/lib/nickserver/reel_server.rb b/lib/nickserver/reel_server.rb
index d2a95ba..9a7053b 100644
--- a/lib/nickserver/reel_server.rb
+++ b/lib/nickserver/reel_server.rb
@@ -23,14 +23,24 @@ module Nickserver
def on_connection(connection)
connection.each_request do |request|
- handler = handler_for(request)
- handler.respond_to params(request), request.headers
+ handle_request(request)
end
end
protected
+ def handle_request(request)
+ puts "#{request.method} #{request.uri}"
+ puts " #{params(request)}"
+ handler = handler_for(request)
+ handler.respond_to params(request), request.headers
+ rescue StandardError => e
+ puts e
+ puts e.backtrace.join "\n "
+ request.respond 500, "{}"
+ end
+
def handler_for(request)
# with reel the request is the responder
Dispatcher.new(request)